I am trying to pass a list of UPNs in to a function to find all Sessionhosts (Virtual Machines) assigned to that UPN in Azure WVD. I would like to match those sessionhost names to the UPN in the list I am passing through and it's just beyond my skill level at this moment. Thank you to anyone who may be able to help me.
The input looks like this.
email1
email2
Output looks like this.
vmname1
vmname2
othervmname1
othervmname2
The output I'd love to be able to figure out would be to create an array, or something, with two columns where id have the output like so:
email1 : vmname1
email1 : vmname2
email2 : othervmname1
email2 : othervmname2
My code is below.
Add-RdsAccount -DeploymentUrl "https://rdbroker.wvd.microsoft.com" | Out-Null
$upnlist = get-content -path c:\path\to\upnlist.txt
#Function to find the session hosts the user is a part of in the WVD Fall 2019 environment.
function Get-FallSessionName {
$Tenants = "tenant,tenant2,tenant3"
ForEach ($upn in $upnlist) {
ForEach ($Tenant in $Tenants) {
$Hostpools = (Get-RdsHostPool -TenantName $Tenant).HostPoolName
foreach ($Hostpool in $Hostpools) {
(Get-RdsSessionHost -TenantName $Tenant -HostPoolName $Hostpool | where-object {$_.AssignedUser -eq $upn}).SessionHostName)
}
}
}
Return $SessionHostName
}
$2019SessionNames = Get-FallSessionName
$2019SessionNames | Out-GridView
Unfortunately I have no way to try this function and see if it works as expected, I have modified your code and gave you a few hints.
IMPORTANT I'm not 100% sure that the property
AssignedUser
ofGet-RdsSessionHost
will return aUserPrincipalName
. You would need to evaluate your code in case it is returning something different.Try and see if it works:
$2019SessionNames
should look like this: