What's the most reliable way to get K1000 to run my PowerShell scripts?
I have a small PowerShell script that deletes a custom registry key and then scans the c:\ drive for a specific file, updating the custom registry key with the path(s) of the file if found. It works just fine if executed manually on the local machine, however I can't get it to run at all when pushed from kbox.
When I push the script to a PC and watch the PC in question, I do see the command window appear. However, the ps1 never executes and I never see powershell.exe in the process list.
I've tried setting the execution policy on the local machine to unrestricted, but that makes no difference.
The ps1 file is attached to the script as a dependency with the "on success" task being set to run a batch file. I've tried each of the following two lines in the body of the batch file:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file blah.ps1
powershell.exe -executionpolicy bypass -file blah.ps1
This is the body of the PowerShell script:
if (Test-Path HKLM:\SOFTWARE\CUSTOM\BLAH) { Remove-Item HKLM:\SOFTWARE\CUSTOM\BLAH -Force -Recurse } [string]$blah = (Get-ChildItem c:\* -File -Filter "blah.exe" -Recurse -Force -ErrorAction SilentlyContinue).fullname if ($blah) { New-Item HKLM:\SOFTWARE\CUSTOM\BLAH -Force
Set-ItemProperty HKLM:\SOFTWARE\CUSTOM\BLAH -Name blahpath -Value $blah
}
Here are the script settings I've tried:
- Run as local system
- Run as user (using local admin account)
- Allow run while logged off
Any ideas as to why kbox is failing to execute this PowerShell script?
4 Comments
[ + ] Show comments
Answers (3)
Please log in to answer
Posted by:
LukeMurnane
8 years ago
Posted by:
jknox
9 years ago
"$(KACE_DEPENDENCY_DIR)\blah.bat" - flip1001 9 years ago
Try to add some LOG actions before to execute the batch that invokes the script.... - StockTrader 9 years ago
my idea at this stage wasn't to act on the script but add a K1000 Script action "Log message..." so you can see in the K1000 Script execution log if you really enter in the On Success branch.
Kind regards,
Marco - StockTrader - StockTrader 9 years ago
Kind regards,
Marco - StockTrader - StockTrader 9 years ago