Skip to content

Instantly share code, notes, and snippets.

@lansalot
Last active December 1, 2021 13:52
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 lansalot/71b958398f34f3f393adf077b0f7b3af to your computer and use it in GitHub Desktop.
Save lansalot/71b958398f34f3f393adf077b0f7b3af to your computer and use it in GitHub Desktop.
Param ([Switch]$All)
$Users = @()
$Disks = @()
0..4 | % {
$ComputerName = "WVD-PROD-$($_)"
Write-host "Checking $ComputerName"
$qusers = ((quser /server:$ComputerName) -replace '^>', '') -replace '\s{2,}', ',' | ConvertFrom-CSV
$qUsers = $qUsers | Where {$_.username -ne "wvdadmin"} | Select *, ComputerName
$qUsers | % {$_.ComputerName = $ComputerName}
$Users += $qUsers
$disks += invoke-command -computername $ComputerName -ScriptBlock {get-disk | Where {$_.location -match 'wvdprofiles'}}
}
ForEach ($User in $Users) {
If ($Disks | Where {$_.Location -match "wvdprofiles-fs\\$($User.username)_S-1" -and $_.pscomputername -eq $User.ComputerName}) {
if ($All) {Write-Output "Matching VHD mounted on $($User.ComputerName) for $($User.UserName)"}
} else {
Write-Output "NO VHD mounted on $($ComputerName) for $($User.UserName)"
}
}
ForEach ($Disk in $Disks) {
$DiskUserName = $disk.location.split("\")[5] -replace ("profile_","") -replace (".vhdx","")
if ($Users | Where {$_.username -eq $diskusername -and $_.computername -eq $disk.PSComputerName}) {
if ($All) {Write-Output "Session found for mounted disk $($DiskUserName) on $($Disk.PSComputerName)"}
} else {
Write-Output "NO session found for mounted disk $($diskusername) on $($Disk.PSComputerName)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment