I am attempting to determine if users in a CSV are active or not, additionally, I want to know if they are service accounts, user accounts, or machine accounts based on OU.
Everything is swell, until I try to output it... The output is on several lines (one for each var).
I would like the output to be on one line (with commas between so I will have a CSV when I am done)... I have tried this twenty different ways with forty different results O_o.
Bonus: add a message for any names that produce errors (i.e. user doesn't exist...) I am thinking of an if/else for that, but have not been able to get the basic output to behave.
I have tried enclosing in parenthesis, concatenating variables, nesting variables... beating my computer with a stick... quietly contemplating my life choices...
$Users = Get-Content C:\ActiveUsers.txt
ForEach ($User in $Users){
$properties = Get-ADUser -Identity $User | select SamAccountName,Enabled,DistinguishedName
if (Select-String -Pattern "UserMgt" -InputObject $properties) { $base = "User" }
if (Select-String -Pattern "ApplSec" -InputObject $properties) { $base = "Service Account" }
if (Select-String -Pattern "WkstnMgt" -InputObject $properties) { $base = "Machine Account" }
write-output $properties.SamAccountName $properties.Enabled $base
#$Output = Write-Output $properties.SamAccountName $properties.Enabled $base
#$Output #| out-file C:\UserStatus-OU2.csv -append
}