검색결과 리스트
storedprocedure에 해당되는 글 1건
글
Introduction
The code underneath shows how to use PowerShell script to encrypt all Stored Procedures in SQL Server once.
Background
For security reason, we put 'WITH ENCRYPTION' to encrypt the stored procedure when we create it. But if we want to update all the stored procedures to encryption, how to do it in one hit? Someone post the C# console application already. Thanks their hint. The point is we need 'Microsoft.SqlServer.Management.Smo' to get it done. Here is my solution to use powershell as same way.
Using the code
First, we need to open PowerShell. You need confirm that your SQL Server version support PowerShell. We are using SQL 2008.
Open 'Microsoft SQL Server Management Studio' -> open 'Object Explorer'-> had better go to the database which you want to update, right click and open 'Start PowerShell', then new PowerShell prompt window will popup.
Modify the code below, change database engine name and database name to yours, copy and paste into the PowerShell window, hit return to run it:
$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."
}
}
}
}
Be patient, it will be finished for a while depend on the number of the Stored Procedures in your database.
출처 : http://www.codeproject.com/Tips/434183/Encrypt-all-Stored-Procedures-with-PowerShell
'-- PowerShell' 카테고리의 다른 글
My first .NET gui in Powershell (0) | 2012.09.06 |
---|---|
Using PowerShell to call a WCF Service (0) | 2012.09.06 |
powershell로 이벤트로그와 프로세스 구하기 (0) | 2011.08.17 |
powershell로 ping 테스트 (0) | 2011.08.17 |
PowerShell로 웹소스 가져오기 (0) | 2011.08.17 |
RECENT COMMENT