2017-06-06 4 views
-4

Ich versuche, das PowerShell-Skript unten mit PSv5 zu verwenden, um einige manuelle Prozesse zu automatisieren, aber es schlägt fehl und ich kann nicht herausfinden, warum. Wenn ich versuche, es in ISE zu debuggen, ich erhalte, ist der folgende Fehler und keine Ausgabedatei erzeugt:PowerShell-Skript schlägt fehl

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 
+0

Wo scheitert es? Was hast du probiert? – Nick

+0

Wie scheitert es? Können Sie die Ausgabe posten? – PrestonM

+0

Bitte [bearbeiten Sie Ihre Frage] (https://stackoverflow.com/posts/44395657/edit), um die tatsächliche Fehlermeldung, die Sie erhalten, einzuschließen. – sodawillow

Antwort

0

Diese

# 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 


# Loop source, files, remove header line, append to the destination file 
ForEach ($SourceFile in $SoureFiles) 
{ 
    Get-Content -Path $SourceFile.FullName | Out-File -FilePath $DestinationFile -Append 
} 

(Get-Content -Path $DestinationFile | Sort-Object { [string]$_.split(',')[1,2] }) | Get-Unique | Out-File -FilePath $DestinationFile -Force 
-1

GELÖST für mich gearbeitet

Das Problem wurde meine PowerShell-Version. Das Skript wurde auf einem Windows 10-System geschrieben, auf dem PSv5.1 ausgeführt wurde. Es ist mir nie in den Sinn gekommen, die Version von PS auf meinem Windows 7-Arbeitssystem (PSv2) zu überprüfen. Sobald ich die PS-Version auf meinem Arbeitssystem aktualisiert hatte, funktionierte das Skript perfekt ...