Tip: Use the New Computername Parameter in Windows PowerShell 2.0

Follow Our Daily Tips

Twitter | Blog | RSS | Facebook

Several cmdlets in Windows PowerShell 2.0 have new parameters. Perhaps the most imme¬diately useful parameter is the −computername parameter, which allows you to work with computers in a remote fashion. The following modified cmdlets now add the –computername parameter.

  • Get-EventLog Gets the events in an event log or a list of the event logs on local or remote computers. The following command uses the −computername parameter with the Get-EventLog cmdlet to retrieve the most recent event from the application log on a remote computer named berlin:
    Get-EventLog -ComputerName berlin -LogName application -Newest 1

  • Get-Process Gets the processes that are running on a local or remote computer. The following command uses the new –computername parameter with the Get-Process cmdlet to obtain a listing of the processes currently running on a remote computer named berlin:
    Get-Process -ComputerName berlin

  • Get-Service Gets the services on a local or remote computer. By using the –computername parameter with the Get-Service cmdlet, you can obtain a listing of the status of all of the services that are defined on a remote computer named berlin:
    Get-Service -ComputerName berlin

  • Set-Service Starts, stops, and suspends a service and changes its properties. The Set-Service cmdlet also has been updated to include the –computername parameter. As shown here, the new parameter is used to connect to a remote computer named berlin and to change the startup type of the service to manual. Because the Set-Service cmdlet is modifying the system state, it uses the –confirm switch to ensure that you are working with both the correct computer and the correct service:
    Set-Service -ComputerName berlin -Name bits -StartupType manual –Confirm

From the Microsoft Press book Windows PowerShell 2.0 Best Practices by Ed Wilson with the Windows PowerShell Teams at Microsoft.

Looking for More Tips?

For more tips on using Microsoft products and technologies, visit the TechNet Magazine Tips library.