Windows PowerShell is a Windows command line shell specially designed for system administrators. It includes an interactive DOS-style command line window and a scripting environment, and can be used independently or jointly. Unlike most shells that receive and send text messages, Windows PowerShell is built on the .NET common language runtime and the .NET Framework to receive and reply to .NET objects. Such features provide new tools and methods for Windows management and configuration.
PowerShell
An important concept in Windows PowerShell is the "cmdlet", a simple, single-function command line tool built in the Shell. Users can use the commands independently, but their effects depend on the application's tasks and environment. Windows PowerShell contains more than 100 basic command lines, and users can write their own command lines and share them with other users.
Like most shells, Windows PowerShell gives you access to your computer's file system. In addition, Windows PowerShell lets you access other stored data, such as the registry and digital signature certificates, just as easily as accessing the file system.
PowerShell in Windows Server 2008 R2 was upgraded to 2.0, which introduced many new features, such as remote management, a complete scripting environment, debug tools, etc. Let's take a closer look at the new features of ISE and enhanced remote functions in PowerShell V2.
1. Integrated Script Environment ISE (Integrated Script Environment)
A basic requirement for PowerShell is to be able to easily write and debug PowerShell scripts. PowerShell v2 is bundled with an integrated script environment ISE (Integrated Script Environment), which makes writing PowerShell scripts easier. ISE includes a script panel, an output panel and A command line panel.
ISE panel
The ISE command line panel is very similar to the PowerShell command line panel. Users can type commands in it and press Enter to execute the command. The execution results of the command will be displayed in the output panel, and the results of all previous command executions can be clearly tracked. The script panel at the top can be used to write and debug scripts. The script panel supports multiple scripts to operate together, making it easy to operate.
In order to help users debug scripts, ISE allows users to set debugging breakpoints in a variety of ways. They can be set manually or automatically under certain special conditions. The latter provides a better operating experience. In the command to set a break point, the user needs to specify the name and coordinates of the debug script.
Set-PSBreakpoint .[Script-File-Name].ps1 -line X
If you want to set multiple break points, you need to separate them with commas when specifying coordinates, such as
Set-PSBreakpoint .[Script-File-Name].ps1 -line X,Y,Z
If you want to set a break point when calling a specific function, you need to use the Set-PSBreakpoint command, the -Command parameter, and the function name:
Set-PSBreakPoint -Command [Name-Of-Function]
The ISE debugger can also set a break point when reading or writing a specific variable. The following is the command to set a break point when reading or writing a variable:
Set-PSBreakpoint -Variable [Variable-Name] -mode read
Set-PSBreakpoint -Variable [Variable-Name] -mode write
After a breakpoint is set, it has a unique identifier. You can delete the breakpoint by deleting the identifier through the Disable-PSBreakpoint command:
Disable-PSBreakpointX
2. Remote function enhancement of PowerShell v2
Another important feature of PowerShell v2 is the enhancement of remote operation capabilities (PowerSell remoting), adding a new command line Invoke-Command. It should be noted that PowerSell remoting currently only supports computers running Vista SP1, Windows Server 2008 and Windows 7, and the corresponding version of the remote management tool WinRM needs to be installed. This means that users can only connect Vista SP1/Win 2008 computers with PowerShell v2 and WinRM installed through PowerShell remoting. Computers with Vista (only PowerShell can be installed) and WinXP systems are not supported.
PowerShell v2 system requirements and improvements
In the CTP pre-release version of PowerShell 2.0, the Invoke-Expression command is used to connect to the remote computer:
Invoke-Expression –computerName atl-fs-001 –command Get-Process
If the user wants to run the Get-Process command on the remote computer atl-fs-001, the new Invoke-Command command can be used:
Invoke-Command –computerName atl-fs-001 –scriptblock
It can be seen that the basic parameters in the two commands are the same. The PowerShell team replaced the Invoke-Expression command with Invoke-Command, and replaced the –command with the –scriptblock parameter. Although there are not many changes in the command, it has improved remote control. Operational stability, safety and performance.
Of course, this command can also support multiple remote computers. If you need to obtain process information from remote computers atl-fs-001, atl-fs-002, and atl-fs-003, you can use the command:
Invoke-Command –computerName atl-fs-001, atl-fs-002, atl-fs-003 –scriptblock
Supports multiple remote computers
Like the Invoke-Expression command, Invoke-Command can connect to the remote computer and run the command, but the connection will be lost immediately. If you need a persistent connection to the remote computer, you can create a PowerShell session with the command:
$objRunspace = New-Runspace atl-fs-001, atl-fs-002, atl-fs-003
If you need more information about the Invoke-Command command, you can get instructions and examples through the following command:
Get-Help Invoke-Command –full | more