Running a powershell script as a kscript isn't working

I have a powershell script that is supposed to harvest the Bitlocker key of a computer, then use that key to force the computer to backup the key to Active Directory. It works when I run it as an administrator by itself. However, when putting it into Kace it doesn't perform as expected.

The script looks like this:
$result = manage-bde -protectors -get c: -type recoverypassword
$id = $result -match "ID" | Out-String
$id = $id.Substring(10)
$revid = $id -replace "`t|`n|`r",""
$finalid = "$revid"
manage-bde -protectors -adbackup c: -id $finalid

Per the documentation I found here, I set up a kscript to run a batch file that calls the powershell script. I have the batch script running the following command:

powershell.exe -ExecutionPolicy Bypass -File "C:\ProgramData\Dell\KACE\kbots_cache\packages\kbots\127\bitlockerBackup.ps1"

The execution policy on the computer is actually set to unrestricted, so that shouldn't be an issue anyway. Any ideas on why this isn't working?

EDIT: I've updated the code to show my latest iteration, wherein I'm only calling the Powershell program once in the batch file. It still doesn't resolve the problem.

3 Comments   [ + ] Show comments
  • Hi pbrandvold, is there a reason for the double powershell.exe command in the begining? - jboling 4 years ago
    • The official documentation has it twice. However, I've tried with just calling powershell once and it doesn't help either. - pbrandvold 4 years ago
  • Just call it once - jgarcia29 4 years ago
  • Did you ever figure this out? - momalle1 2 years ago
    • Unfortunately no, but honestly I didn't try any of the solutions in the comments - shortly after posting this I ended up creating a script to remote into computers using powershell and run this script through that instead. - pbrandvold 2 years ago
      • Thank you. I have tried them to no avail :(. - momalle1 2 years ago

Answers (2)

Posted by: JasonEgg 4 years ago
Red Belt
That article is odd, I don't know why they hard-code the script dir. I would use "Launch a program"  with these settings:
Directory: $(KACE_SYS_DIR)\WindowsPowerShell\v1.0
File: powershell.exe
Parameters: -nologo -executionpolicy bypass -WindowStyle hidden -file $(KACE_DEPENDENCY_DIR)\bitlockerBackup.ps1
Posted by: HISDTechGuy 4 years ago
Senior Yellow Belt
Is this for x64 machines? if so try to specify the 64 bit powershell using %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe

if the KACE agent is running in 32 bit it will run the 32 bit powershell, which has issues dealing with the OS
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