-4
我想用PSv5下面的PowerShell腳本來自動化一些手動過程,但它保持失敗,我不明白爲什麼。當我嘗試調試它在ISE,我得到的是生成以下錯誤,並沒有輸出文件:PowerShell腳本失敗
Get-Content : Cannot bind argument to parameter 'Path' because it is null.
At line:15 char:53
+ $HeaderLine, ${$DestinationFile} = Get-Content -Path <<<< $SourceFile.FullName
+ CategoryInfo : InvalidData: (:) [Get-Content], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetContentCommand
# BEGIN SCRIPT
#
# Collect all the files in the directory
$SoureFiles = Get-ChildItem -Path 'C:\raw' -Filter '*.txt'
# Create the destination file
$DestinationFile = (New-Item -Path 'c:\done' `
-Name ('CombinedSources-' + (Get-Date -Format 'ddMMMyyyy') + '.txt') `
-ItemType File -Force).FullName
$DestinationFile
# Loop source, files, remove header line, append to the destination file
ForEach ($SourceFile in $SoureFiles)
{
$HeaderLine, ${$DestinationFile} = Get-Content -Path $SourceFile.FullName
${$DestinationFile}`
| Out-File -FilePath $DestinationFile -Append
}
# Sort the Destination file content and replace with sorted unique lines
(Get-Content -Path $DestinationFile `
| Sort-Object { [string]$_.split(',')[1,2] }) `
| Get-Unique `
| Out-File -FilePath $DestinationFile -Force
#
#END SCRIPT
它在哪裏失敗?你有什麼嘗試? – Nick
它是如何失敗?你可以發佈輸出嗎? – PrestonM
請[編輯你的問題](https://stackoverflow.com/posts/44395657/edit)包括你得到的實際錯誤信息。 – sodawillow