-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

Dgan
  • 10,077
  • 1
  • 29
  • 51

1 Answers1

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..

Jimbo
  • 2,529
  • 19
  • 22