Wednesday, February 14, 2018

Script To Get Version of Powershell

Hello again!

I have time today to add another post on this blog.  This script is what I use to get a list of all servers and what version of Powershell is installed on the server.

We are using this script to determine which servers will need to be updated to version 5:

$adServers = $()

$adServers += get-adcomputer -Filter * -Properties * -SearchBase "OU=ou1,DC=abc,DC=com" |Select-Object Name

$adServers += get-adcomputer -Filter * -Properties * -SearchBase "OU=ou2,DC=abc,DC=com" |Select-Object Name

foreach ($server in $adServers) {

Invoke-Command -ComputerName $server.Name -ScriptBlock { $PSVersionTable.PSVersion } | export-csv -append C:\PSVersionsbyServer.csv



}


As in other posts, I defined a variable called $adServers to hold the names of servers.  There are two OUs that contain server information.  That is why I have two get-adcomputer statements. 

In the FOREACH loop, I used Invoke-Command to query each server for the Powershell version.  I like using Invoke-Command because is saves from having to do a lot of extra coding such as creating and entering PSSessions.
 

No comments:

Post a Comment