Custom Inventory Rule Powershell failing in KACE but not locally?
I'm trying to run a custom inventory rule to pull the name of a VM's Hyper-V Host server with the following powershell script:
(get-item "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters").GetValue("HostName")
I need to pull this information so I can make smart labels to manage VM's based on what host they are located on. I can run the powershell on the VM locally and get the desired results. I can save the .ps1 file to an accessible file share and call it on the VM locally and get the desired results. However, whenever I try to run it as an inventory rule I get errors as results.
This is the custom inventory rule I'm using:
ShellCommandTextReturn(powershell -ExecutionPolicy Bypass -file "\\FILESHAREPATH\hypervhost.ps1" )
as I said before I can run powershell -ExecutionPolicy Bypass -file "\\FILESHAREPATH\hypervhost.ps1" on the VMand get the desired results.However, when the inventory rule runs this is what I get:
|get-item : Cannot find path 'HKLM:\SOFTWARE\Microsoft\Virtual |
Machine\Guest\Parameters' because it does not exist.
At \\FILESHAREPATH\hypervhost.ps1:1 char:8
+ $key = get-item "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters"
+ CategoryInfo : ObjectNotFound: (HKLM:\SOFTWARE\...uest\Paramete
rs:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetIt
You cannot call a method on a null-valued expression.
At \\FILESHAREPATH\hypervhost.ps1:2 char:1
+ CategoryInfo : InvalidOperation: (:) , RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Additionally, If I try to add JUST the powershell without calling a script like this:
ShellCommandTextReturn(Powershell "(get-item 'HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters').GetValue('HostName')" )
The powershell again works if I run it from the VM but if I try it this way in the K1000, the custom inventory rule does not even populate. Not even with errors. I can't figure out why the code would work when run on the VM but not when run within the rule. Is there anything obvious anyone sees that I am doing wrong?
Please log in to answer
Posted by: Desktop Jockey 3 years ago