Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

PowerShell - scripting - skip Encrypted\CLR Stored Procedures

$
0
0

Hi all,

Forgot where I got the code below from but, how would I skip Encrypted\CLR procedures because, I get error below...

Message
Executed as user: Loginname A job step received an error at line 81 in a PowerShell script. The corresponding line is '$MyScripter.Script($proc)|out-null'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Exception calling "Script" with "1" argument(s): "The StoredProcedure '[dbo].[myrpocname]' cannot be scripted as its data is not accessible."  '.  Process Exit Code -1.  The step failed.


#STORED PROCEDURES
if($procs -ne $null)
{
	foreach ($proc in $procs)
	{
		#Assuming that all non-system stored procs have proper naming convention and don''t use prefixes like "sp_"
		if ( $proc.Name.IndexOf("sp_") -eq -1 -and $proc.Name.IndexOf("xp_") -eq -1  -and $proc.Name.IndexOf("dt_") -eq -1)
		{
			$fileName = $proc.name"Scripting SP $fileName"
			$scriptfile = "$rootDrive\DatabaseScripts\$sqlDatabaseName\$strDate\StoredProcedures\$filename.sql"
			New-Item $rootDrive\DatabaseScripts -type directory -force | out-null
			New-Item $rootDrive\DatabaseScripts\$sqlDatabaseName -type directory -force | out-null
			New-Item $rootDrive\DatabaseScripts\$sqlDatabaseName\$strDate -type directory -force | out-null
			New-Item $rootDrive\DatabaseScripts\$sqlDatabaseName\$strDate\StoredProcedures -type directory -force | out-null
			# SetScriptOptions
			$MyScripter.Options.FileName = $scriptfile
			#AppendTofile has to be ''true'' in order that all the procs'' scripts will be appended at the end
			$MyScripter.Options.AppendToFile = "true"
			$MyScripter.Script($proc)|out-null
		}
	} 

Thanks

gv


Sword


Viewing all articles
Browse latest Browse all 12963

Trending Articles