Import-Module activedirectory $opt = read-Host 'Would like to see a list of DNs from which to choose? (y/n)' switch ($opt) { y{Get-ADOrganizationalUnit -Filter 'Name -like "*"' | FT Name, DistinguishedName -A} n{} } Write-Host 'Enter the full DN of the OU you want to scan (for users): ' -ForegroundColor green $dn = Read-Host "example: ou=company,dc=domain,dc=local" get-aduser -SearchBase "$dn" -filter * -property * | select name, lastlogondate | Sort-Object lastlogondate Write-Host 'there are your users'
This runs fine, but if the read-host answer is Y, then the last line "write-host 'there are your users'" is outputted BEFORE the results are. However, if the answer is N, then the last line is outputted last. What is wrong with my script that inputting a Y makes the script process out of order?
- Edited by SlickUSA 15 hours 4 minutes ago