MicrosoftВ® Windows PowerShell(TM) Step By Step (Step By Step (Microsoft))
In addition to using traditional programs and commands from the CMD.exe command interpreter, we can also use the commandlets (cmdlets) that are built into PowerShell. Cmdlets are name-created by the Windows PowerShell team to describe the commands that are built into PowerShell. They are like executable programs, but they take advantage of the facilities built into Windows PowerShell, and therefore are easy to write. They are not scripts, which are uncompiled code, because they are built using the services of a special .NET Framework namespace. Windows PowerShell comes with more than 120 cmdlets that are designed to assist the network administrator or consultant to leverage the power of PowerShell without having to learn the PowerShell scripting language. These cmdlets are documented in Appendix A. In general, the cmdlets follow a standard naming convention such as Get-Help, GetEventLog, or Get-Process. The get cmdlets display information about the item that is specified on the right side of the dash. The set cmdlets are used to modify or to set information about the item on the right side of the dash. An example of a set cmdlet is Set-Service, which can be used to change the startmode of a service. An explanation of this naming convention is seen in Appendix B.
Installing Windows PowerShell
It is unfortunate that Windows PowerShell is not installed by default on any of the current Windows operating systems, including Windows Vista. It is installed with Exchange Server 2007 because Exchange leverages Windows PowerShell for management. This is a tremendous advantage to Exchange admins because it means that everything that can be done through the Exchange Admin tool can also be done from a PowerShell script or cmdlet.
Windows PowerShell can be installed on Windows XP SP2, Windows Server 2003 SP1, and Windows Vista. Windows PowerShell requires Microsoft .NET Framework 2.0 (or greater) and will generate the error shown in Figure 1-1 if this level of the .NET Framework is not installed.
To prevent frustration during the installation, it makes sense to use a script that checks for the operating system (OS), service pack level, and .NET Framework 2.0. A sample script that will check for the prerequisites is
strComputer = "." wmiNS = "\root\cimv2" wmiQuery = "Select name from win32_Product where name like '%.NET Framework 2.0%'" wmiQuery1 = "Select * from win32_OperatingSystem" WScript.Echo "Retrieving settings on " & _ CreateObject("wscript.network").computername & " this will take some time ..." Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS) Set colItems = objWMIService.ExecQuery(wmiQuery) Set colItems1= objWMIService.ExecQuery(wmiQuery1,,RtnImmedFwdOnly) If colItems.count <>1 Then WScript.Echo ".NET Framework 2.0 is required for PowerShell" Else WScript.Echo ".NET Framework 2.0 detected" End If For Each objItem1 In colItems1 osVER= objItem1.version osSP= objItem1.ServicePackMajorVersion Next Select Case osVER Case "5.1.2600" If osSP < 2 Then WScript.Echo "Service Pack 2 is required on Windows XP" Else WScript.Echo "Service Pack",osSP,"detected on",osVER End If Case "5. 2.3790" If osSP <1 Then WScript.Echo "Service Pack 1 is required on Windows Server 2003" Else WScript.Echo "Service Pack",osSP,"detected on",osVER End if Case "XXX" WScript.Echo "No service pack is required on Windows Vista" Case Else WScript.Echo "Windows PowerShell does not install on Windows version " & osVER End Select
Deploying Windows PowerShell
After Windows PowerShell is downloaded from http://www.Microsoft.com/downloads, you can deploy Windows PowerShell to your enterprise by using any of the standard methods you currently use. A few of the methods some customers have used to accomplish Windows PowerShell deployment are listed next.
-
Create a Microsoft Systems Management Server (SMS) package and advertise it to the appropriate Organizational Unit (OU) or collection.
Create a Group Policy Object (GPO) in Active Directory (AD) and link it to the appropriate OU.
If you are not deploying to an entire enterprise, perhaps the easiest way to install Windows Powershell is to simply double-click the executable and step through the wizard.
Note | To use a command line utility in Windows PowerShell, launch Windows PowerShell by using Start | Run | PowerShell. At the PowerShell prompt, type in the command to run. |
Категории