1
我的劇本是有點完整,但我想補充的過程中的一些處理它:PowerShell的等待和釋放
#Call Bluezone to do file transfer
& "C:\Program Files (x86)\BlueZone FTP\6.1\Bzftpf.exe" /F"ccaihfs.zft"
#Variable Declarations
$source = "\\fhnsrv01\home\aborgetti\Documentation\Stage\"
$dest = "\\fhnsrv01\home\aborgetti\Documentation\Stage\orig"
$archive = "\\fhnsrv01\home\aborgetti\Documentation\Stage\archive"
#First copy the original file to the orig folder before any manipulation takes place
Copy-item $source\*.EDIPROD $dest
# Now we must rename the items that are in the folder
Switch(GCI \\fhnsrv01\home\aborgetti\Documentation\Stage\*.EDIPROD){
{(GC $_|Select -first 1).substring(176) -match "^834"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"834Dailyin$($Matches[1]).txt"};Continue}
{(GC $_|Select -first 1).substring(176) -match "^820"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"820Dailyin$($Matches[1]).txt"};Continue}
{(GC $_|Select -first 1) -match "NO INPUT"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"NOINPUTin$($Matches[1]).txt"};Continue}
{(GC $_|Select -first 1) -match ""}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName Default {"Could not find 834 or 820 qualifier in file $_"};Continue}
}
#move files older than 1 month to archive
$date = (get-date).AddDays(-31)
GCI \\fhnsrv01\home\aborgetti\Documentation\Stage\*.txt| Where{$_.CreationTime -lt (get-date).adddays(-31)}| move-item -destination $archive
此作品燦爛的是,唯一的問題是這一行:
& "C:\Program Files (x86)\BlueZone FTP\6.1\Bzftpf.exe" /F"ccaihfs.zft"
這是調用一個FTP程序。問題是這個過程需要一段時間。結果與腳本的其餘部分一起被處理。但是PowerShell的速度非常快,它只是在文件傳輸完成之前做它必須做的事情。
我在FTP程序中設置了一些自動配置選項,以便它在文件傳輸完成後自動關閉。這應該釋放該程序的PID/mem。
我知道PS可以處理這種情況。只是不知道如何。
我想我想要做的就是把PS擱置,直到完成處理,然後當它釋放PID時,完成腳本。
正確。讓我嘗試! – Hituptony
謝謝!像夢一樣工作! – Hituptony