/build/static/layout/Breadcrumb_cap_w.png

KScript saying that a Powershell is executed successfully, but nothing is changed.

I'm attempting to run a Powershell script across our network and I'm testing it out before I roll it out to all the computers. 

I've got the script written up and if I run it from the machine that I'm testing it on it will work fine.  If, however I run it through a KScript it will say that the script executed successfully but when I watch the machine I'm testing it on I get an extremely fast flash of a Powershell window with a red error message in it.  I can't grab a screenshot of the error and I've tried adding a sleep to the end of the script to make it slow down so that I can see the message to no avail.

Ultimately KACE thinks that the script ran successfully, but none of the work that the script is supposed to do has been performed.

Info:
The file I'm running is a .ps1 file.
Our network is set up to only allow powershell scripts to run locally (hence the KACE distribution).
I have the file uploaded to the KScript and am using the $(KACE_DEPENDENCY_DIR) line to point to it.  I believe this should allow the script to run locally.
I have the local system account running the file.
The script is set to run whether or not someone is logged in.
Our K1000 is version 6.0.101865 if that helps.  

Let me know if you need more information.

Thanks,
Moorish.

1 Comment   [ + ] Show comment
  • I am having this same issue, it seems that its running with lowered permissions regardless of what I tell KACE to do. have you found a fix for this yet? - HISDTechGuy 10 years ago

Answers (5)

Posted by: jknox 10 years ago
Red Belt
2
What is the exact structure of your task in the kscript?

As a side note:

Bear in mind that the K1000 only knows that the kscript ran successfully, not that your Powershell script did.

Also know that the KACE agent is 32 bit.  Sometimes you have to use things like SysNative to get around that limitation.

http://www.samlogic.net/articles/sysnative-folder-64-bit-windows.htm
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187%28v=vs.85%29.aspx
http://scottiestech.info/2009/06/20/calling-a-32-bit-system-command-from-a-script-in-x64-windows/

Comments:
  • I've made sure that the Powershell script runs successfully on its own. The hiccup comes when I add KACE to the mix.

    As for the Kscript itself, all it is supposed to do is verify the file exists and run it.

    The exact line is pointing to powershell.exe and setting the script itself as a parameter: “c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” with params “$(KACE_DEPENDENCY_DIR)\Script.ps1”

    If I point KACE to run the PS1 file directly then I get a 193 error. Is this the wrong way to go about running the powershell? - Moorish 10 years ago
Posted by: Moorish 10 years ago
White Belt
1
Still having issues with this but it seems to be that the problem has to do with some sort of Permission that KACE is using.  I'm having it run through KACE with the same account that works when running the script on its own, but it's still crashing before anything can be done, including "-ErrorAction Inquire"


Posted by: h2opolo25 10 years ago
Red Belt
1
Does the script itself need a user to be logged in? Sometimes using local system will not work for some scripts and you need to make it run as a logged in user or a specific user. Since it runs I'm guessing it's not so much a KACE issue as it is a script or permissions issue.

Also to view what the error is you can log the error messages to a file.
http://stackoverflow.com/questions/17420474/how-to-capture-error-messages-thrown-by-a-command-in-powershell 

Comments:
  • I've tried it with users and without. When I try it with the User it does the same thing.

    Also, I attempted to add that bit to the script and the script doesn't create the log file. It's like the script is being run but at the first line. - Moorish 10 years ago
Posted by: HISDTechGuy 7 years ago
Senior Yellow Belt
1
I found the issue with this, figured Id post for other people even though this is an old thread.

The issue was with Kace running as a 32 bit process on a 64 bit machine, when it called powershell it did it as a 32 bit process which has issues when dealing with windows.

use this to call the correct version of powershell
%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe

I use this bat file when I need to run something on both 64 and 32 bit

if exist "%SYSTEMDRIVE%\Program Files (x86)\" (
     %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file Dosomething.ps1  -verb RunAs
) else (
  %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file Dosomething.ps1  -verb RunAs
)
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ