没有错误,但 PowerShell 代码不工作

No errors but PowerShell code not working

此脚本中没有错误,但我正在摸不着头脑,因为我已经检查了 csv 数据并且名字和姓氏完全匹配(因此不应将错误写入日志)。然而,它不是跳过写入日志,而是总是这样做。所以,我不得不注释掉 Continue 行,否则脚本将无法完成。

此外,如果重新雇用日期是从今天开始的未来 8 天,我想启用一个用户对象,但这似乎也不起作用(对我来说没有明显的错误)。有人可以检查我的逻辑吗?这不是完整的脚本,只是我找不到任何问题的地方。谢谢

`$CSVLine = "C:\scripts\adp\Test ADP Import spec.csv"
$ErrorLog = "C:\scripts\adp\ADPProcessErrors.csv"
[xml]$DivLocFile = Get-Content -Path "C:\Scripts\adp\DivLocData.xml"
$DocumentRoot = $DivLocFile.DocumentElement
$UserLocationCode = @{}
$a = Get-Date

ForEach ($row in (Import-Csv $CSVLine)) {

    #Skips over Terminiated employees
If ($CSVLine.EmployeeStatus -eq "Terminated") { Continue }
    #Gets the user's First and Last name
    $User = Get-ADUser -LDAPFilter ("(sAMAccountName=" + $Row.sAMAccountName + ")") -Properties *

    If ($User -eq $Null) {
        #If there is no First and Last name this will throw an error and go on to the next record.
        ($Row.sAMAccountName + ",AD Object Not Found") | Out-File -FilePath $ErrorLog -Append

        Continue
         }  
        #Checks whether First or Last names don't match
        If (($User.givenName -ne $CSVLine.'First Name') -or ($User.sn -ne $CSVLine.'Last Name')) { 

        ($Row.sAMAccountName + ",givenName and sn property mismatch") | Out-File -FilePath $ErrorLog -Append

        #Continue
         }
        #Enables a disabled user if they have a hire date 8 days in advance of today's date. 
        If (($CSVLine.'Date of hire/rehire' -gt ($a)) -and ($CSVLine.'Date of hire/rehire') -le ($a.AddDays(8)) -and (!($User.Enabled)))  {

        (Set-ADUser -Enabled $True -Identity $User)
        ("SID:" + $Row.sAMAccountName + ", User:[" + $User.givenName + " " + $User.sn + "] Re-Hire date is in range. Account enabled.") | Out-File -FilePath $ErrorLog -Append
        }`

看起来你的很多 IF 语句都在使用 $CSVLine,而它们看起来应该使用 $row