我正在撰寫一個輸入 .csv 的腳本并嘗試進行操作,然后捕獲到單獨的 .csv 中,但由于某種原因,我似乎無法將捕獲資訊輸入到 csv 中。我收到錯誤訊息,“Export-csv:無法處理引數,因為引數“name”的值無效。更改“name”引數的值并再次運行該操作。”
我感謝大腦的任何輸入。
#imports a csv and does somthing with the data. The columns in the csv are specified by the $($_.'columnName')
Import-Csv -Path 'PathToMyCSV.csv' | ForEach-Object{
#Print associated User
Write-Host "$($_.ModifiedEmail)" -ForegroundColor Yellow -NoNewline;
Write-Host " is the user's email prefix, " -NoNewline
#Print PC name to be moved
Write-Host "SD-LT-$($_.PCName)" -ForegroundColor Yellow -NoNewline;
Write-Host " is the PC they use, and " -NoNewline
#Print The OU the computer is moving to
Write-Host "$($_.OU)" -ForegroundColor Yellow -NoNewline;
Write-Host "is the OU the computer needs to go in!"
$pcname = "SD-LT-$($_.PCName)"
Try {
Get-ADComputer SD-LT-$($_.PCName) | Move-ADObject -TargetPath $($_.OU)
}
Catch {
Write-Host $_ -ForegroundColor Magenta
$pcname | Export-csv -Path 'PathToAnotherCSV.csv' -Append -Force
}
}
uj5u.com熱心網友回復:
嘗試創建一個PSCustomObject.
[PSCustomObject]@{'pcname'=$pcname} | Export-csv -Path 'PathToAnotherCSV.csv' -Append -Force
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/348780.html
下一篇:使用Get-AppxPackage/Remove-AppxPackage將包排除(foreach-notlike)列入白名單
