cmdlet-series

PowerShell 2.0: One Cmdlet at a Time 17 Receive-Job

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Receive-Job cmdlet. What can I do with it? Retrieve the results of a background job which has already been run. Example: Retrieve the results for the job with ID 1 and keep them available for retrieval again. (The default is to remove them) Receive-Job -Id 1 -Keep How could I have done this in PowerShell 1.

PowerShell 2.0: One Cmdlet at a Time 18 Remove-Job

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Remove-Job cmdlet. What can I do with it? Remove existing background jobs from the current session. Examples: Remove the job with ID 1. Remove-Job -Id 1 Use the Get-Job cmdlet to retrieve all jobs and pipe it through to Remove-Job to remove them all. Get-Job | Remove-Job How could I have done this in PowerShell 1.

PowerShell 2.0: One Cmdlet at a Time 16 Get-Job

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-Job cmdlet. What can I do with it? Get background jobs from the current session as objects. Examples: Get background jobs from the current session. Get-Job Get background jobs from the current session which contain the Get-WMIObject cmdlet. Get-Job -Command “Get-WMIObject” Store a job in a variable and examine it’s methods and properties.

PowerShell 2.0: One Cmdlet at a Time 15 Start-Job

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Start-Job cmdlet. What can I do with it? Start a background job on the local computer. This allows you to take back your console session whilst you wait for the job to complete. Examples: Start a background job to run Get-Service on the local computer. Start-Job -ScriptBlock {Get-Service} This will display the status of this job in your current session and allow you to continue working in the session - then retrieve the results at a later time.

PowerShell 2.0: One Cmdlet at a Time 14 Start-Process

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Start-Process cmdlet. What can I do with it? Start a process on the local computer. Examples: Start an instance of Notepad Start-Process Notepad Open the file Test.txt using its associated application Notepad Start-Process C:\Scripts\Test.txt How could I have done this in PowerShell 1.0? You could have used the .NET System.Diagnostics.Process class and the Start method.

PowerShell 2.0: One Cmdlet at a Time 13 Clear-EventLog

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Clear-Eventlog cmdlet. What can I do with it? Clear the Event Log on a local or remote computer. Example: Clear the Application Event Log on the remote computer Server01 Clear-EventLog -LogName Application -ComputerName Server01 How could I have done this in PowerShell 1.0? You could have used the Get-EventLog cmdlet and the Clear method of the System.

PowerShell 2.0: One Cmdlet at a Time 12 Write-EventLog

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Write-EventLog cmdlet. What can I do with it? Write an event in a Windows Event Log on a local or remote machine. Example: Write an Error event into the Application log on Server01 with source CustomApp1, EventID 8750 and Error Message. Write-EventLog -computername Server01 -logname Application -source CustomApp1 -eventID 8750 -entrytype Error -message “CustomApp1 has experienced Error 9875”

PowerShell 2.0: One Cmdlet at a Time 11 Add-Computer

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Add-Computer cmdlet. What can I do with it? Join a local computer to a domain or workgroup Example: Join the current computer to the Test domain, place the computer account in the Servers OU and use the Restart-Computer cmdlet to reboot the computer to complete the process. Add-Computer -domainname Test -OUPath ‘OU=Servers,DC=test,DC=local’; Restart-Computer

PowerShell 2.0: One Cmdlet at a Time 10 Restart-Computer

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Restart-Computer cmdlet. What can I do with it? Restart a local or remote computer Example: Immediately restart the computer Server01. Restart-Computer -ComputerName Server01 -Force How could I have done this in PowerShell 1.0? You could have used the Win32_OperatingSystem WMI Class and the Win32Shutdown method. (Get-WmiObject -Class Win32_OperatingSystem -ComputerName Server01).Win32Shutdown(2) Alternatively the Systinternals tool PSShutdown could be used to restart a local or remote computer.

PowerShell 2.0: One Cmdlet at a Time 9 Checkpoint-Computer

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Checkpoint-Computer cmdlet. What can I do with it? Create a system restore point on XP or Vista systems. Example: Create a system restore point called Pre-RegistryChange Checkpoint-Computer -description “Pre-RegistryChange” How could I have done this in PowerShell 1.0? You could have used the SystemRestore WMI class and the CreateRestorePoint method $SystemRestore = [wmiclass]"\\.\root\default:systemrestore" $SystemRestore.