Header Ads

Header ADS

PS: Cross Reference Script

Part 2 of 3

The second report I needed to generate was a list of users who are current users of the new VDI environment, which was rolled out a few days prior. This will identify the list of users who are still entitled to use the old and the VDI solutions. Those highlighted in yellow indicates which users we can safely revoke access to the old VDI solution:

Script:

$NewVDIGroups = "New_VDI_Dept1", "New_VDI_Dept2",
  "New_VDI_Dept3", "New_VDI_Dept4"

$OldVDIGrp = Get-ADGroup "Old_VDI_Group"
$CSVName = ".\UserMembers.csv"
$DeleteCount = 0

Start-Transcript -Path .\GroupAnalysis.txt
foreach ($ADGroup in $NewVDIGroups) {
    Write-Host ""
    Write-Host "Checking $ADGroup..." -ForegroundColor Magenta
    $ADUsers = Get-ADGroupMember -Identity $ADGroup 
    foreach ($ADUser in $ADUsers){
        Write-Host $ADUser.Name.PadRight(32) -NoNewline
        if ((Get-ADUser $ADUser -Properties MemberOf | 
   Select-Object -ExpandProperty MemberOf) -contains $OldVDIGrp) 
   {
    Get-ADUser $ADUser -Properties Department | 
     Select-Object SAMAccountName, 
         Name, 
         Department, 
         @{Name='RetailGroup'; Expression={$ADGroup}} | 
     Export-Csv $CSVName -Append
    Write-Host "`tMember!!" -ForegroundColor Yellow
            $DeleteCount ++
            }
        else {
            Write-Host "`tNon-Member" -ForegroundColor Gray
            }
        }
    }
 Write-Host "Total: $DeleteCount" -ForegroundColor Cyan

No comments

Powered by Blogger.