Jonathan Medd’s Blog
Scripting. Powershell, VBScript, Windows, Active Directory & Exchange.VMWare. All that kind of stuff…..-
PowerShell 2.0: One Cmdlet at a Time #58 Export-PSSession
Posted on February 5th, 2010 No commentsContinuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Export-PSSession cmdlet.
What can I do with it?
Export commands from a remote PowerShell session into a module saved on the local system.
Example:
Establish a remote session with Test01 using New-PSSession. Use Invoke-Command to initiate the use of the BITSTransfer module. Export the commands from the BITSTransfer module into a module saved on the local system and called BITSCommands.
$session1 = New-PSSession -ComputerName Test01 Invoke-Command -Session $session1 -ScriptBlock {Import-Module BITSTransfer} Export-PSSession -Session $session1 -Module BITSTransfer -OutputModule BITSCommands -AllowClobber
The exported files are stored within your PowerShell profile folder.
The contents of the BITSCommands.psd1 file are below:
You could make use of this module at a later date with:
Import-Module BITSCommands
Extras:
Ravikanth Chaganti has an excellent post covering this cmdlet in more detail here.
How could I have done this in PowerShell 1.0?
Remoting did not exist in PowerShell 1.0, you would have needed to use Remote Desktop to run an interactive session on a remote server.
-
PowerShell 2.0: One Cmdlet at a Time #57 Import-PSSession
Posted on February 5th, 2010 No commentsContinuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Import-PSSession cmdlet.
What can I do with it?
Import commands from a Remote PowerShell session into the current session, for instance from a remote session on another computer.
Example:
Establish a remote session with Test01 using New-PSSession. Use Invoke-Command to initiate the use of the BITSTransfer module. Use Import-PSSession to make the contents of the BITSTransfer module available in the local session even though the BITSTransfer module has not been imported on the local computer.
Note: Technically I could just have imported the BITSTransfer module on the local machine, however this example is to demonstrate that potentially any module could be brought across to the local session.
$session1 = New-PSSession -ComputerName Test01 Invoke-Command -Session $session1 -ScriptBlock {Import-Module BITSTransfer} Import-PSSession -Session $session1 -Module BITSTransfer
Confirm the contents of the BITSTransfer module is now available in the local session.
Get-Command *Bits* -CommandType Function
Extras:
Ravikanth Chaganti has an excellent post covering this cmdlet in more detail here.
How could I have done this in PowerShell 1.0?
Remoting did not exist in PowerShell 1.0, you would have needed to use Remote Desktop to run an interactive session on a remote server.
-
PowerShell 2.0: One Cmdlet at a Time #56 Disconnect-WSMan
Posted on February 4th, 2010 No commentsContinuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Disconnect-WSMan cmdlet.
What can I do with it?
Disconnect a connection previously made to a remote computer using WS-Management with the Connect-WSMan cmdlet.
Example:
Disconnect from the remote server Test01 using WS-Management .
Disconnect-WSMan -ComputerName Test01
How could I have done this in PowerShell 1.0?
Support for the use of WS-Management in PowerShell is provided as part of the 2.0 release.
-
PowerShell 2.0: One Cmdlet at a Time #55 Disable-WSManCredSSP
Posted on February 3rd, 2010 No commentsContinuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Disable-WSManCredSSP cmdlet.
What can I do with it?
Disable CredSSP configuration on a computer. Note: this cmdlet requires running from an elevated PowerShell session.
Example:
Disable the CredSSP configuration on the local computer which has previously been enabled for client CredSSP via Enable-WSManCredSSP. Confirm this has been successful with Get-WSManCredSSP.
Disable-WSManCredSSP -Role client Get-WSManCredSSP
You will notice that the computer is no longer configured for CredSSP authentication.
How could I have done this in PowerShell 1.0?
Support for the use of WS-Management in PowerShell is provided as part of the 2.0 release.
-
PowerShell 2.0: One Cmdlet at a Time #54 Get-WSManCredSSP
Posted on February 3rd, 2010 No commentsContinuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-WSManCredSSP cmdlet.
What can I do with it?
View the CredSSP configuration on the local computer. Note: this cmdlet requires running from an elevated PowerShell session.
Example:
View the CredSSP configuration on the local computer which has previously been enabled for client CredSSP via Enable-WSManCredSSP.
Get-WSManCredSSPYou will notice the client part has been enabled, but not the server.
How could I have done this in PowerShell 1.0?
Support for the use of WS-Management in PowerShell is provided as part of the 2.0 release.
-
PowerShell 2.0: One Cmdlet at a Time #53 Enable-WSManCredSSP
Posted on February 3rd, 2010 No commentsContinuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Enable-WSManCredSSP cmdlet.
What can I do with it?
Enable CredSSP authentication on a computer allowing a user’s credentials to be passed to a remote computer for authentication. (Think authentication for background jobs on remote computers.) Note: this cmdlet requires running from an elevated PowerShell session.
Example:
Enable user credentials on the local computer to be sent to the remote computer Test02.
Enable-WSManCredSSP -Role client -DelegateComputer Test02.test.local
You will notice that you are prompted to confirm and given a warning that making this change will allow the remote computer to have access to your username and password.
How could I have done this in PowerShell 1.0?
Support for the use of WS-Management in PowerShell is provided as part of the 2.0 release.
-
PowerShell 2.0: One Cmdlet at a Time #52 New-WSManSessionOption
Posted on February 2nd, 2010 No commentsContinuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the New-WSManSessionOption cmdlet.
What can I do with it?
Create a session option hash table for use with the WS-Management cmdlets Get-WSManInstance, Set-WSManInstance, Invoke-WSManAction and Connect-WSMan.
Example:
Create a session option hash table for use with the Set-WSManInstance cmdlet to update the HTTPS listener created with New-WSManInstance .
$options = New-WSManSessionOption -OperationTimeout 1000 -SkipRevocationCheck Set-WSManInstance winrm/config/listener -SelectorSet @{address="*";transport="https"} -SessionOption $options
How could I have done this in PowerShell 1.0?
Support for the use of WS-Management in PowerShell is provided as part of the 2.0 release.
-
PowerShell 2.0: One Cmdlet at a Time #51 Remove-WSManInstance
Posted on February 1st, 2010 No commentsContinuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Remove-WSManInstance cmdlet.
What can I do with it?
Remove a management resource that has been previously created for use with WS-Management.
Example:
Check for existing HTTPS Listeners. Remove the existing HTTPS listener created with New-WSManInstance . Check again to confirm its removal.
Get-WSManInstance winrm/config/listener -selectorset @{Address="*";Transport="https"} Remove-WSManInstance winrm/config/listener -SelectorSet @{address="*";transport="https"} Get-WSManInstance winrm/config/listener -selectorset @{Address="*";Transport="https"}
You will notice that you recieve a nasty red error when trying to retrieve it after it has been removed.
How could I have done this in PowerShell 1.0?
Support for the use of WS-Management in PowerShell is provided as part of the 2.0 release.
-
PowerShell 2.0: One Cmdlet at a Time #50 Set-WSManInstance
Posted on January 29th, 2010 No commentsContinuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Set-WSManInstance cmdlet.
What can I do with it?
Change the properties of a management resource for use with WS-Management.
Example:
Set the Enabled property of the HTTPS listener created with New-WSManInstance to false, effectively disabling it. Tip: watch out for case sensitivity in ValueSet
Set-WSManInstance winrm/config/listener -SelectorSet @{address="*";transport="https"} -ValueSet @{Enabled="false"}
How could I have done this in PowerShell 1.0?
Support for the use of WS-Management in PowerShell is provided as part of the 2.0 release.
-
PowerShell 2.0: One Cmdlet at a Time #49 New-WSManInstance
Posted on January 28th, 2010 No commentsContinuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the New-WSManInstance cmdlet.
What can I do with it?
Create an instance of a management resource for use with WS-Management.
Example:
Create an instance of a management resource for use with WS-Management using HTTPS.
You need to specify a certificate for use with this listener since it is HTTPS. For testing purposes it is possible to create a self-signed certificate within IIS. Open the Create Self-Signed Certificate Wizard and enter a name.
Export it to C:\Temp
Import the pfx file into the Personal Certificate Store
For the New-WSManInstance cmdlet you will require the thumprint of this certificate, you can find this using PowerShell and the Certificate Provider.
Get-Childitem -path cert:\CurrentUser\My | Format-List FriendlyName,Thumbprint
Creation of the new WSManInstance using HTTPS is as follows:
New-WSManInstance winrm/config/Listener -SelectorSet @{Address="*";Transport="HTTPS"} -ValueSet @{Hostname="Test01";CertificateThumbprint="01F7EB07A4531750D920CE6A588BF5"}
You can verify this remotely using the Get-WSManInstance cmdlet.
Get-WSManInstance winrm/config/listener -selectorset @{Address="*";Transport="https"} -computername Test01
How could I have done this in PowerShell 1.0?
Support for the use of WS-Management in PowerShell is provided as part of the 2.0 release.





















