Created
September 8, 2015 14:18
-
-
Save Dan1el42/0d6e5f6aa86055364830 to your computer and use it in GitHub Desktop.
This file contains 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
$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