Tuesday, May 20, 2014

Getting the Event Log from another machine with PowerShell

If you have to manage a server farm of more than one computer, PowerShell can be of use if you have access to it.

If you don't have access to it, you may have to setup PowerShell Remoting (don't ask me how, because I haven't done that myself yet).

PS C:\> Get-EventLog -ComputerName somecomputer -LogName Application -Newest 10

Note that I'm using the -Newest paramter and not using the -After parameter, because apparently this means you will need to wait for PowerShell to go through the entire log, instead of stopping at a certain point.

Using a specific version of PowerShell

If you inspect $PSVersionTable you'll see a few different versions of things being used with PowerShell in the current session, specifically look for $PSVersionTable.PSVersion. By default the most latest version will be used.

To launch a specific version of PowerShell you can pass the -version switch, e.g. for PowerShell v2:

c:\ powershell -version 2