64 Bit powershell
I was trying to run a native powershell script and no matter what I did it wouldnt run. Apparently it was accessing part of the registry which required the 64bit powershell. I dont even fully understand what the hell happened but I worked on it for hours and hours and it ran fine for my in powershell unelevated but I could not get it to run via kace. It would always say it couldnt find the path in the registry and looked like it was referencing c/windows/system32/ and then the registry path.
In an effort to provide information as well as take from here, this was the fix after opening a ticket:
Set-Alias Start-PowerShell64 "$env:windir\sysnative\WindowsPowerShell\v1.0\powershell.exe"
Start-PowerShell64 get-childitem -Path etc etc (powershell command)
So apparently kace uses a 32 bit vers of PS? I dont know, dont care, just annoying.
Good luck.
Answers (1)
As the KACE agent is x86, this would be the workaround. You can prepend your powershell script with the following code block to execute it in x64:
# To execute in x64 powershell #
if ($PSHOME -like "*syswow64*") {
Write-Output 'Relaunching as x64'
& (Join-Path ($PSHOME -replace 'syswow64', 'sysnative') powershell.exe) `
-File $Script:MyInvocation.MyCommand.Path `
@args
Exit
}
######################
# Rest of script goes in here #