2017-12-07 3 views
0

저는이 문제를 해결하기 위해 노력해 왔지만 지금까지 아무 것도 작동하지 않았습니다. 1/여러 파일을 선택하고 하드 코딩 된 값 (예 : "DIAB`r`n")을 파일 내용의 시작 부분에 추가 한 다음 다른 볼륨에 쓸 수 있습니다. 여러 문장을 사용해야하나요 아니면 내가 할 수있는 것입니까? 내가하려고하면Get-ChildItem을 수행 할 때 파일에 텍스트 추가

# Find the file/s .HL7, move to a new destination and change the filename to add "DIAB-" 
# to the front - this is working 
Get-ChildItem -Path $DiabetesPath | 
    Where-Object { (!$_.PSIsContainer -and $_.Name -like "*.HL7") } | 
    Move-Item -Destination $DestinationPath -PassThru | 
    Rename-Item -NewName {"DIAB-" + $_.Name} 

# this is what is not working - after files moved to destination trying to add some text 
# to the start of the file content 
Get-ChildItem $DestinationPath -Recurse -Filter DIAB*.HL7 | ForEach-Object 
{ 
    $content = Get-Content $_.FullName 
    Set-Content $_.FullName -Value "DIAB`r`n", $content 
} 

, 그것은 말한다 : 내가 뭔가를 입력하면

 
cmdlet ForEach-Object at command pipeline position 2 
Supply values for the following parameters 
process[0]: 

이 가고 계속 :

 
process[1]: 
process[2]: 
... 

하지 내가 지금까지 가지고하는 것은이 문을 사용하려고 할 것입니다 무슨 일이 일어나고 있는지.

답변

0

와우! {의 위치가 무엇인가에 영향을 줄 것이라는 것을 깨닫지 못했습니다.

{ForEach-Object 옆으로 이동하면 작동합니다.

Get-ChildItem $DestinationPath -Recurse -Filter DIAB*.HL7 | ForEach-Object { 
    $content = Get-Content $_.FullName 
    Set-Content $_.FullName -Value "DIAB`r`n", $content 
} 
관련 문제