Last active
September 12, 2016 10:28
-
-
Save markwragg/0967da2b612bc690f764bd23318aa508 to your computer and use it in GitHub Desktop.
Powershell script to get the installed version of Powershell from multiple servers in an Active Directory domain, optionally filtered by part of an OU name (e.g a location).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -version 2.0 | |
[CmdletBinding()] | |
param ( | |
[ValidateSet("Dublin","London”,"Tokyo","Sydney","")][string]$location | |
) | |
Import-Module ActiveDirectory -Cmdlet get-adcomputer | |
$servers = get-adcomputer -filter {Enabled -eq $true -and OperatingSystem -Like "Windows*"} -property Enabled,OperatingSystem | ?{$_.DistinguishedName.contains($location)} | |
$servers | ForEach-Object{ | |
$computer = $_; | |
if(test-connection $computer.name -TimeToLive 10 -Quiet -Count 1 -ea 0){ | |
$PSVersion = "$(Invoke-Command -Computer $computer.Name -ScriptBlock { $PSVersionTable.PSVersion.Major })" | |
Write-Verbose "$($computer.name) : $($computer.operatingsystem) : $PSVersion" | |
new-object -TypeName PSObject -Property @{Name=$computer.name;OS=$computer.operatingsystem;PSVersion=$PSVersion} | |
}else{ | |
Write-Verbose "$($computer.name) : Unable to connect"; | |
} | |
} | export-csv "PSVersion-$location-$(get-date -format yyyy-MM-dd).csv" -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment