【发布时间】:2015-08-12 15:34:27
【问题描述】:
所以我有这个非常基本的 powershell 脚本来将文件备份到我们的网络驱动器:
Function Backup {
param ($backupSource)
#Define backup location
$backupTarget = '\\192.168.0.247\Public'
#Make sure we're targeting a folder
If (!(Test-Path $backupSource -pathtype container)) {
[System.Windows.Forms.MessageBox]::Show("Target must be a folder" , "Error", 0)
Exit
}
#Make sure we have access to the backup location
DO {
$test = Test-Path $backupTarget
If (!$test) {
$loop = [System.Windows.Forms.MessageBox]::Show("Is the WiFi on? I can't reach the public drive. Maybe try again in a second." , "Internet Connection Unavailable" , 5)
If ($loop -eq 'Cancel') {
Exit
}
}
} WHILE (!$test)
Copy-Item $backupSource $backupTarget -recurse
}
我试图让它在右键菜单中工作,让它显示没问题,它会执行,但我不知道如何成功地为其提供 $backupSource 参数。
我正在使用我的默认密钥处理HKEY_CLASSES_ROOT\Directory\shell\NASBackup\command。我已经尝试了我能想到的"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -File "C:\Windows\System32\Backup.ps1" "%1" 的所有组合。有人可以帮我解决这里的语法吗?
【问题讨论】:
标签: windows powershell registry contextmenu