Datasheet

UNDERSTAND THE BASICS OF POWERSHELL 19
Administering
Service Delivery
PART I
prompt to your command that requires additional input by the executor before
it continues.
Script Administration Tasks
In addition to o ering a robust environment for executing cmdlets, PowerShell
also provides an integrated environment for writing scripts. Like one-liners, scripts
allow you to execute a series of commands all at once, without having to enter each
command individually. For example, if you have a list of commands that you run
every time a server is promoted to a domain controller, you can put those com-
mands into a script.  en, the next time you install Active Directory on a server,
you run the script once instead of executing each command.
Scripts are also useful if you want to apply some logic to a series of commands. For
example, you could write a script to determine the last time your users logged in
and then disable the accounts and move them to a di erent Organizational Unit
(OU) if its been over 90 days. In this case, the script would make the decisions
about what to do with the user accounts.
Create PowerShell Scripts
You can create a script using any standard text editor that you’re comfortable with.
However, there are advantages to using the built-in PowerShell ISE discussed earlier. If you
have the ISE available to you, it makes sense to use it rather than a standard text editor.
When you create scripts, you type in the commands just as you would if you were
typing them directly into the shell. You have the option of inserting comments into
your scripts by placing a pound symbol (
#
) in front of the comment, as shown in the
following snippet:
# This is a comment.
Get-Process
In PowerShell v2, you also have the ability to use block comments.  is allows you
to comment out large portions of text in your script  les. To use a block comment,
you start the comment with
<#
and end it with
#>
. Everything in between is consid-
ered a comment, as demonstrated in the following snippet:
<#
This is a block comment.
The next line of code will execute the Get-Process cmdlet
which will display a list of running processes on the screen
#>
Get-Process
c01.indd 19c01.indd 19 5/12/2011 1:07:48 PM5/12/2011 1:07:48 PM