所以我正在使用这个 Powershell 脚本:Set-RunOnce https://www.powershellgallery.com/packages/WindowsImageConverter/1.0/Content/Set-RunOnce.ps1
当我将驱动器号硬编码到 (E:\ServerInstall.ps1) 中时,它就像一个魅力。但我想确保这个脚本可以从 USB 插入的任何驱动器号运行。
如何在注册表中获取此更改的驱动器号?
我首先尝试使用-ExecutionPolicy Bypass,但这也没有太大变化。
我也试过这个:
$getusb = Get-WmiObject Win32_Volume -Filter "DriveType='2'" 。.\Set-RunOnce.ps1 设置-RunOnce -Command
'%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe `-ExecutionPolicy Unrestricted -File $getusb.Name\ServerInstall.ps1'
--> $getusb.Name\ServerInstall.ps1 最终在注册表中被硬编码,但它不知道 $getusb.name 是什么,所以脚本没有启动。
. .\Set-RunOnce.ps1
Set-RunOnce -Command '%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe `
-ExecutionPolicy Unrestricted -File (wmic logicaldisk where drivetype=2)
ServerInstall.ps1'