Datasheet
UNDERSTAND THE BASICS OF POWERSHELL 23
Administering
Service Delivery
PART I
from
http://msdn.microsoft.com/en-us/windows/bb980924.aspx
. A er
you install the SDK, use the following command to create a self-signed certi cate:
makecert.exe -r -pe -n “CN=PowerShell Signing Cert” -ss MY -a sha1 -eku i
1.3.6.1.5.5.7.3.3
You can then run the following PowerShell command to verify that the certi cate
was successfully created:
PS C:\> Get-ChildItem cert:\currentuser\my -codesigning
Directory: Microsoft.PowerShell.Security\Certificate::currentuser\my
Thumbprint Subject
---------- -------
DA747C75B468FCF2701FC844799B3DCE44B5F512 CN=PowerShell Signing Cert
Now that you’ve obtained your certi cate, you can use the
Set-
AuthenticodeSignature
cmdlet to sign your PowerShell script. You’ll need
to pass the certi cate object as a parameter in the cmdlet. You can do this by
assigning the certi cate to a variable and then referencing the variable in the
Set-AuthenticodeSignature
cmdlet. For example, if you wanted to sign
a script called
UpdateSiteTopology.ps1
, you would run the following
commands:
PS C:\> $certificate = Get-ChildItem cert:\currentuser\my -codesigning
PS C:\> Set-AuthenticodeSignature UpdateSiteTopology.ps1 $certificate
A er you sign the script, you’ll notice that a signature block has been added to the
end of the le. is block represents the encrypted hash. If you modify the script, be
sure to re-sign it so this encrypted hash value is updated.
Use Variables in a Script
You could write scripts to execute one command a er another, but PowerShell
scripts can be more than mere substitutes for batch les. In order to take your
scripting to the next level and write more powerful scripts, you need to learn some
of the basics of scripting, starting with variables.
Variables are nothing more than a way to temporarily store data for later use. In
PowerShell, variables are easy to work with because they can hold any type of data,
such as text, numbers, or whole objects.
c01.indd 23c01.indd 23 5/12/2011 1:07:49 PM5/12/2011 1:07:49 PM