Loyall
asked on
Powershell: Export variables to csv
Hi,
I have a powershell script that gives me some output on screen.
I would like to have this exported into a csv file.
It must be quite simple I guess, but with my lack of Powershell knowledge, i can not get it done.
The script displays:
doe, john migrated
smith, john no longer available
jackson, jack not migrated
I have a powershell script that gives me some output on screen.
I would like to have this exported into a csv file.
It must be quite simple I guess, but with my lack of Powershell knowledge, i can not get it done.
The script displays:
doe, john migrated
smith, john no longer available
jackson, jack not migrated
Import-Module ActiveDirectory
$users =Get-ADUser -filter * | select samaccountname | foreach {
$Username = $_.sAMAccountname
$ADuser = Get-ADUser -identity $Username –properties *
$Name = $AdUser.CN
$UserOU1 = $ADuser.CanonicalName.ToString().Split('/')[3]
$UserOU2 = $ADuser.CanonicalName.ToString().Split('/')[1]
if ($userOU1 -match "employees") {
$status = "migrated"
write-host $Name $status -ForegroundColor green
}
elseif ($userOU2 -match "out of service") {
$status = "No longer available"
write-host $Name $status -ForegroundColor white
}
else {
$status = "not migrated"
write-host $Name $status -ForegroundColor red
}
}
You should be able to add "Export-Csv C:\test.csv" at the end of your script as line 23.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Subsun, thanks a lot ! Exactly what i needed !!