Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 PowerShell syntax error.

Author  Topic 

the1gadget
Yak Posting Veteran

55 Posts

Posted - 2009-03-16 : 08:45:36
Hi All

(apologies if this is the wrong forum)

I have a Job that is a Power shell script. This script works perfectly as a ps1 script when run from the command line, but when trying to run it from a job it gives me a syntax error.

Does any one have any ideas as to where to start looking.
here is the function

function Try
{
param
(
# Check that the script blocks are there
[ScriptBlock]$Command = $(throw "The parameter -Command is required."),
[ScriptBlock]$Catch = { throw $_ },
[ScriptBlock]$Finally = {}
)
&{
# Set the error trapping
$local:ErrorActionPreference = "SilentlyContinue"
trap
{
trap
{
&
{
trap { throw $_ }
&$Finally
}
throw $_
}
$_ | & { &$Catch }
}
&$Command
}
&{
trap { throw $_ }
&$Finally
}
}


The script barfs up at the first [ScriptBlock]

the1gadget
Yak Posting Veteran

55 Posts

Posted - 2009-03-16 : 10:31:47
Hi All

But I think I have found the answer. taken from
http://concentratedtech.com/content/index.php/2008/06/sql-server-2008-powershell-no-no-no-no-no/

========================================8<========================================

The PowerShell cmdlets are likely being built on SQL Management Objects (SMO), a .NET Framework class set that was introduced in SQL2005. You’ll apparently be able to use PowerShell in SQL Server Agent job steps, which is mega-cool, and PowerShell v1 is a pre-requisite for installing SQL2008.

But they have created a SQL Server-specific version of Windows PowerShell, which is what you use if you want to use SQL Server 2008 cmdlets or the new provider. And this new console is closed - you cannot add more functionality to it by using Add-PSSnapin.

To say that this is “stupid” would be unkind to all the stupid people out there. This “closed console” is stupid on a level heretofore unknown. The SQL team is basically taking a great, all-purpose administrative tool and locking it down. They’re returning us to the good old days of Windows NT, when everything was administered by its own, separate, non-integrated admin tool. THIS SUCKS.

Even better? Some collection names - e.g. ,”Databases,” as in $server.Databases - are case-sensitive, in defiance of everything else PowerShell does. Some of PowerShell’s built-in discoverability features are broken in this closed console, removing the ability to work with individual snap-ins, for example. COULD THIS SUCK ANY MORE?
========================================8<========================================

Nuff said
Go to Top of Page
   

- Advertisement -