Kace2000 powershell post install script
I am trying to run powershell scripts as post installation tasks on the kace 2000.
I add the scripts as applications and give the folowing parameters
powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file "script.ps1"
The above comes from this: http://www.itninja.com/question/how-to-run-a-powershell-command
During installation all the task will fail, and by examining the xml file i see the problem is the path where the command is run.
The path is something like c:\kace\task_name\powershell.exe and it should be C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
I tried to add this to the parameters like this:
"C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe" -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file "script.ps1"
But this just gave the following path in the XML file
c:\kace\task_name\C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
How should this be fixed?
Bok
0 Comments
[ + ] Show comments
Answers (2)
Answer Summary:
Please log in to answer
Posted by:
chucksteel
8 years ago
Top Answer
I have found the most reliable method is to create a zip archive that contains the ps1 file and a batch script. The batch script just runs powershell. I then call the batch script as the parameter for the post-install task.
Comments:
-
Thank you, this seem to work. - bok 8 years ago
Posted by:
SMal.tmcc
8 years ago
best way to trouble shoot is look at the tasks.xml to see how it is formatted.
by entering this for the parameter:
powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file "script.ps1"
you get
<Task ID="482">
<Name>powershell example</Name>
<WorkingDirectory>%systemdrive%\KACE\Applications\482</WorkingDirectory>
<CommandLine><![CDATA["%systemdrive%\KACE\Applications\482\powershell.exe" -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file "script.ps1"]]></CommandLine>
<Parameters></Parameters>
<PostTaskAction>None</PostTaskAction>
<KACETaskType>Application</KACETaskType>
<FileType>Exe</FileType>
<Type>PO</Type>
<Guid>1577137778ebd2</Guid>
</Task>
By adding double quotes around the entire command:
"powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file script.ps1"
you get
<Task ID="482">
<Name>powershell example</Name>
<WorkingDirectory>%systemdrive%\KACE\Applications\482</WorkingDirectory>
<CommandLine><![CDATA["powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file script.ps1"]]></CommandLine>
<Parameters></Parameters>
<PostTaskAction>None</PostTaskAction>
<KACETaskType>Application</KACETaskType>
<FileType>Exe</FileType>
<Type>PO</Type>
<Guid>15771389517259</Guid>
</Task>
just make sure you have no spaces in the ps1 name.
Comments:
-
Great! Thanks. I won't be able to test it out till tomorrow as im off work now.
Yet i am thinking, whn i call iy this way, will poweshell be able to locate the script file?
What i mean is poweshell is opened from system32 folder and script is located in /kace/application folder - bok 8 years ago -
The quotations partly fixed the problem.
Now the new problem is that the command is run with the quotations, which also results in failure.
I made the task pass by editing the XML manually from this:
<CommandLine><![CDATA["powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file script.ps1"]]></CommandLine>
to this:
<CommandLine><![CDATA[powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file script.ps1]]></CommandLine>
How do i tell kace not to include the working dir, and not to include quotetaions? - bok 8 years ago