Author Posts

January 27, 2017 at 2:19 pm

hi,

Any documentation linke would be helpfull. i want to encrypt functions and triggers

$db = (new-Object Microsoft.SqlServer.Management.Smo.Server("[DataBase Engine Name]")).Databases.Item("[DataBase 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."
}
}
}
}

yours scinelrey

January 27, 2017 at 4:21 pm

You'd likely get a better answer from a SQL Server-specific forum. You're not really "using PowerShell," here, you're using SQL Server Management Objects. Consider StackExchange, or perhaps the PASS forums, to find folks who are a bit more specialized in SQL Server and SMO.