Good day, all!
I am total noob to powershell scripting. My manager has tasked me with working on an integration script for a new system we will be using. I want to piggyback off of the headers in our HR integration file that we generate nightly and feed those values into a CSV file that has different headers. The new system requires these specific headers.The reason for piggybacking, is because we don't have an attribute in AD defined for UserStatus. The value in that column is critical to the new system. It will determine if a user is added or deleted from the system.
Here is my current script:
$dateString = Get-Date -Format yyyyMMdd
$users = Import-Csv -Path "c:\scripts\XXXXXX\ActiveDirectory_$dateString.csv" -Header `
'PreferredName,Last,EmployeeID,Email,UserStatus'
$OutFile = "C:\Scripts\XXXXXX\Test\DeltaFeed_$dateString.csv"
$Outheader = "Funds,Firstname,Lastname,Employeenumber,Email,Action"
Add-Content -Path $OutFile -Value $Outheader
$userFunds = "XXXX"
$action = if ($_.UserStatus -eq 'A')
{'A'}
elseif ($_.UserStatus -eq 'T')
{'D'}
ForEach ($user in $users)
{
$outstring = $userFunds + "," + $_.PreferredName + "," + $_.Last + "," + $_.EmployeeID + "," + $_.Email + "," + $action
Add-Content -Path $OutFile -Value $outstring
}
The problem I am running into is the out file has the headers, but no values in each column. I am not quite sure what I am doing incorrectly here. I am not used to this syntax.