首页 > 解决方案 > PowerShell Script Running Issues - Has to be ran twice in ISE and does not work when executed from file explorer location

问题描述

I'm currently experiencing some problems with importing/editing existing registry keys into a printer driver location.

After some searching I found that Set-ItemProperty is the exact thing I need to rewrite subkey areas within the registry, however, I've had a lot of trouble running it.

When the code is put directly into the PowerShell console it works perfectly and updates the file in just the way I want it to.

When the code is open and ran in Powershell ISE it has to run several times consecutively (spammed around 3 times) for it works.

When the code is ran from its PS1 file from its file explorer location (C:\user\RW Sandbox\Documents\Printerscripts) then it doesn't work at all, regardless of whether or not I've spammed the run invocation.

This is the code I was using (although mine includes a lot more hex than this example):

Set-ItemProperty -Path "HKLM:\SOFTWARE\Xerox\PrinterDriver\V5.0\Xerox Global Print Driver PCL6\DeviceSettings" -Name "CachedXrxDeviceSettings" -Type "binary" -Value ([byte[]](0x10,0x00,0x00,0x00,0x01,0x00,0x07,0x20,0x2b,0x16,0x58,0x02,0x00,0x00,0x00,0x00,0x4d,0x53,0x43,0x46,0x00,0x00,0x00,0x00,0x70,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03))

Within the PowerShell, the execution policy is currently unrestricted as initially, I believed that this might have been a permission issue.

标签: powershell

解决方案


推荐阅读