我的powershell腳本如下。我嘗試在遠程機器上壓縮文件夾。我不想在ScriptBlock
內部放置Zip函數,因爲它將用於腳本的其他部分。從遠程腳本塊調用函數
function Zip{
param([string]$sourceFolder, [string]$targetFile)
#zipping
}
$backupScript = {
param([string]$appPath,[string]$backupFile)
If (Test-Path $backupFile){ Remove-Item $backupFile }
#do other tasks
$function:Zip $appPath $backupFile
}
Invoke-Command -ComputerName $machineName -ScriptBlock $backupScript -Args $appPath,$backupFile
在$backupScript
,它給錯誤$函數:拉鍊線:
+ $功能:郵編$ APPPATH $ backupFile
+ ~~~~~~~~ 意外表達式或語句中的標記'$ appPath'。