Skip to content

Instantly share code, notes, and snippets.

@Dan1el42
Created September 8, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dan1el42/0d6e5f6aa86055364830 to your computer and use it in GitHub Desktop.
Save Dan1el42/0d6e5f6aa86055364830 to your computer and use it in GitHub Desktop.
$Desktops = Get-Content -Path c:\temp\desktoplist.txt
# The ArrayList class allows the array to expand dynamically
$DesktopDetails = New-Object -TypeName System.Collections.ArrayList
foreach ($Desktop in $Desktops) {
switch -wildcard ($Desktop) {
'UK*'{$servers = @('UKSite1.com', 'UKSite2.com')}
'US*'{$servers = @('USSite1.com')}
'SG*'{$servers = @('SGSite1.com')}
}
$DesktopDetail = foreach ($server in $servers) {
Get-BrokerDesktop -machinename domain\$Desktop -Adminaddress $server |
Select-Object -Property DNSName, SessionState
}
if ($DesktopDetail) {
$DesktopDetails += $DesktopDetail
}
else {
'No machine with name {0} found on server(s): {1}' -f $Desktop, ($Servers -join ',')
}
}
$DesktopDetails | Export-Csv -Path c:\temp\desktopdetails.txt -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment