Import-module 'ActiveDirectory' $getadusers = @() $filter = @() $samaccountnamelijst = @() $Header = 'Samaccountname' $CSV = '.\Gemeentenet.csv' $Extension = $null $import = @() Add-Content -Value $Header -Path $CSV $getadusers = Get-aduser -filter * foreach ($entry in $getadusers){if ($entry -ne $null){$samaccountnamelijst += $entry.samaccountname}} foreach ($sam in $samaccountnamelijst){Add-Content -Value $sam -Path $CSV} $Deelnemerlijst = @() $allusers = import-csv $csv foreach ($Deelnemeruser in $allusers){if ($Deelnemeruser -match $deelnemer){$Deelnemerlijst += $Deelnemeruser}} $Deelnemerlijst | export-csv .\$Deelnemer.csv $entry = $null $username = 'othext' $CSV = '.\Gemeentenet.csv' $import = @() $filter = @() $import = import-csv $csv foreach ($entry in $import){if ($entry -match $username){$filter += $entry.samaccountname}} $filter = $filter -split "@{samaccountname=" |sort $filter = $filter -split "$username" | sort $filter = $filter -split "}" | Sort -Descending $nummer = [int]$filter[0] $nummer++ Add-content -Value $volledigesamaccountname -path $csv