powershell catch 导出到 csv 不工作
powershell catch export to csv not working
我正在编写一个脚本,该脚本被提供一个 .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
}
}
尝试创建 PSCustomObject
.
[PSCustomObject]@{'pcname'=$pcname} | Export-csv -Path 'PathToAnotherCSV.csv' -Append -Force
我正在编写一个脚本,该脚本被提供一个 .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
}
}
尝试创建 PSCustomObject
.
[PSCustomObject]@{'pcname'=$pcname} | Export-csv -Path 'PathToAnotherCSV.csv' -Append -Force