powershell

PowerShell 2.0: One Cmdlet at a Time 36 Get-PSSession

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-PSSession cmdlet. What can I do with it? Retrieve remote PowerShell sessions created in the current session. Examples: Get all current sessions Get-PSSession Get session 3. Get-PSSession -Id 3 Get all sessions open with Test01. (Not well illustrated in this screenshot since there is only one server with sessions open, but you get the idea)

PowerShell 2.0: One Cmdlet at a Time 33 New-PSSession

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the New-PSSession cmdlet. What can I do with it? Establish a persistent connection to a computer that has been enabled for PowerShell remoting. Examples: Establish a persistent remote PowerShell connection to Test01 and store it in the variable $session. Then use the Enter-PSSession cmdlet with the Session parameter to use that session. $session = New-PSSession -ComputerName Test01 Enter-PSSession -Session $session

PowerShell 2.0: One Cmdlet at a Time 34 Invoke-Commmand

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Invoke-Command cmdlet. What can I do with it? Run commands on local or remote computers and return the results. Examples: Establish a persistent remote PowerShell connection to Test01 using New-PSSession and store it in the variable $session. Then return the results for which services begin with T. $session = New-PSSession -ComputerName Test01 Invoke-Command -Session $session -ScriptBlock {Get-Service | Where-Object {$_.

PowerShell 2.0: One Cmdlet at a Time 31 Enter-PSSession

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Enter-PSSession cmdlet. What can I do with it? Open an interactive PowerShell session with a computer which has been enabled for PowerShell remoting. Example: Open a session with the server Test01 and see which services begin with the letter T. Enter-PSSession -ComputerName Test01 Get-Service | Where-Object {$_.name -like ‘T*’} You will notice that the prompt has changed to

PowerShell 2.0: One Cmdlet at a Time 32 Exit-PSSession

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Exit-PSSession cmdlet. What can I do with it? Exit an interactive PowerShell session that has been opened on a computer which has been enabled for PowerShell remoting. Example: Leave an interactive PowerShell session with a computer which has been enabled for PowerShell remoting. Exit-PSSession You will notice that the prompt has changed back from

PowerShell 2.0: One Cmdlet at a Time 30 Enable-PSRemoting

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Enable-PSRemoting cmdlet. What can I do with it? Configure a computer to be enabled for PowerShell remoting. Tip: Make sure you run this cmdlet from an elevated process. Example: Configure the computer Test01 to be enabled for PowerShell remoting. Enable-PSRemoting This will produce output similar to the below; note the command was run on a Windows Server 2008 64bit system

PowerShell 2.0: One Cmdlet at a Time 29 Import-Counter

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Import-Counter cmdlet. What can I do with it? Create objects by importing performance data in BLG, CSV or TSV files. Example: Import as objects data in a BLG file previously exported from Export-Counter or the Performance Monitor GUI. $performancedata = Import-Counter -Path Memory.blg How could I have done this in PowerShell 1.0? To manage performance data contained in a BLG file you could have used the Performance Monitor GUI to import it and view the contents.

PowerShell 2.0: One Cmdlet at a Time 28 Export-Counter

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Export-Counter cmdlet. What can I do with it? Take performance objects generated from the Get-Counter or Import-Counter cmdlets and export them as log files. Note: this cmdlet requires Windows 7 or Windows Server 2008 R2 or later. Examples: Retrieve some memory performance data from the local machine and export it to the standard Performance Monitor output file BLG.

PowerShell 2.0: One Cmdlet at a Time 27 Test-ComputerSecureChannel

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Test-ComputerSecureChannel cmdlet. What can I do with it? Test the secure channel between the local computer and the domain and optionally fix if necessary. Example: Test the secure channel on the current computer Test-ComputerSecureChannel Note: this will return a Boolean value of True or False as seen below; if you wish for more detailed information use the -Verbose parameter.

PowerShell 2.0: One Cmdlet at a Time 26 New-WebServiceProxy

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the New-WebServiceProxy cmdlet. What can I do with it? Make use of an available web service. Examples: The website http://www.webservicex.net has a number of available web services which you can use with the New-WebServiceProxy cmdlet. Find the current weather for Southampton, UK. $weather = New-WebServiceProxy -uri “http://www.webservicex.net/globalweather.asmx?wsdl" $weather.GetWeather(‘Southampton’, ‘United Kingdom’) Note: to find what cities were available within the UK to query I used the GetCitiesByCountry method.