-1

I want to encrypt all stored procedures in existing database so i tried with shell scripts

$db = (new-Object Microsoft.SqlServer.Management.Smo.Server("SQL_instance")).Databases.Item("[DB_name]") 

Foreach ($sp in $db.StoredProcedures){
  if(!$sp.IsSystemObject){
    if (!$sp.IsEncrypted){
        $sp.TextMode = $false;
        $sp.IsEncrypted = $true;
        $sp.TextMode = $true;
        try
{
            $sp.Alter();
}
catch{
Write-Host "$sp.Name fail to encrypted."
}

     }
  }
}

it is working on one of my local server but not on client's server Source for this

i am getting following error Error

4
  • "I want to encrypt all stored procedures in existing database " -what could possibly go wrong! Commented Jun 12, 2014 at 11:33
  • @MitchWheat is there any different versions for shellscripts?? Commented Jun 12, 2014 at 11:49
  • Please do not assume the encryption is, well, secure. Commented Jun 12, 2014 at 16:12
  • Try this, stackoverflow.com/a/8478071/930186 Its not PowerShell, but it works! Commented Mar 9, 2015 at 9:11

1 Answer 1

0

You script works fine for me - so I would suspect that you may need to run powershell in administrator mode or elevate its privileges..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.