使运行一次注册表编辑以执行Power Shell脚本

时间:2016-07-28 18:24:41

标签: windows powershell regedit

我正在尝试重启后恢复电源shell脚本。 (我正在重新启动到"应用"我已做过的注册表更改")我相信我可以通过对Run Once键进行注册表编辑来完成我想要的任务。我查看了this question,但我无法在启动时执行类似的代码。进行注册表编辑,并在启动时运行,因为它消失了,但它没有完成安装。

$part2 = Get-ChildItem C:\Windows\ccmcache\ -Recurse -Force -Filter Full_Druva_Reinstall_part2.ps1
$FullPath = $part2.FullName
$KeyPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce"

new-itemproperty -Path $KeyPath -Name !Install-Druva -propertytype String -value "Powershell -executionPolicy Unrestricted -File $FullPath"

编辑 此scrpit位于SCCM包内,任何解决方案都需要自动执行,无需用户输入。

2 个答案:

答案 0 :(得分:0)

打开任务计划程序一般会给出一个名称>运行用户是否登录>启动时触发> 行动

程序/脚本将是powershell.exe

参数

-ExecutionPolicy Bypass -File" C:\ myscripts.ps1"

enter image description here

答案 1 :(得分:0)

我无法使Run Once Registry工作,如果非管理员登录,它也无法使用admin cred。我也无法在power shell因为我的环境都是Win7和power shell v4。

我使用的解决方案是在SCCM中创建一个任务序列,它运行我的脚本的第1部分,重新​​启动,然后运行第2部分。