Unable to execute powershell script

Hello Everyone!
I have a task to create a windows local group and add its permission on all the available drives except C.
I was provided with the script and it runs fine when I execute it locally on system. Although, when I try to execute the same through BigFix, the permissions are applied on all the drives except for Drive D.
I tried using createfile method as well as tried deploying script directly and executed it but the results were same. Also, I have the BigFix client deployed in D Drive in my Infra. Could someone help that what is the error here? Tried generating logs as well but there is no error received anywhere to troubleshoot further
Below is the script:
#Start Logging
Start-Transcript -Path C:\LogFiles\AdminFileAccessUAC.log -Append -NoClobber

#Create new local group named 'AdminFileAccessUAC’
New-LocalGroup -Name ‘AdminFileAccessUAC’ -Description ‘Contains same members as local Administrators’

#Get list of ‘administrators’ group members and add them to 'AdminFileAccessUAC" group
Get-LocalGroupMember ‘Administrators’ | Add-LocalGroupMember -group ‘AdminFileAccessUAC’

#Loop through disk drives D: to Z:

and run icacls /grant AdminFileAccessUAC:(CI)(OI)F

to grant full control to group ‘AdminFileAccessUAC’ on disk root and folder hierarchy

$grant="/grant"
$permission=":(CI)(OI)F"
$useraccount=“AdminFileAccessUAC”

68…90 | foreach {{ #67=ascii code for C; 90=ascii code for Z
$path= [char]$_ + ":"
invoke-expression -command (‘icacls $path $grant “${{useraccount}${{permission}”’)
}

#Stop Logging
Stop-Transcript

I am using the below command to execute the script
action uses wow64 redirection {not x64 of operating system}
waithidden powershell -ExecutionPolicy Bypass -file “D:\Deploy PS\ps_uac.ps1”

The agent log could provide more useful info about the error. Take a look at the agent log on the failing computer. The log is located here:
C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData__Global\Logs

It should contains a trace for the failing “waithidden” command, with error details.

1 Like

Hi FDA,
Sorry for replying late wasn’t well these days.
Below are the client logs for this action:
At 12:48:07 +0000 - mailboxsite (http://bcgbigfix.den02.hosting.com:52311/cgi-bin/bfgather.exe/mailboxsite544956121)
Relevant - Deploy PS Script (fixlet:680664)
At 12:48:08 +0000 -
ActionLogMessage: (action:680664) Action signature verified for Execution
ActionLogMessage: (action:680664) starting action
At 12:48:08 +0000 - actionsite (http://bcgbigfix.den02.hosting.com:52311/cgi-bin/bfgather.exe/actionsite)
Wow64 redirection disabled. action uses wow64 redirection {not x64 of operating system} (action:680664)
Command succeeded delete No ‘D:\Program Files\BigFix__BESData\CustomSite_HostingPatching\createfile’ exists to delete, no failure reported (action:680664)
Command succeeded delete “C:\Windows\Temp\script.ps1” (action:680664)
Command succeeded createfile until (action:680664)
Command succeeded move __createfile “C:\Windows\Temp\script.ps1” (action:680664)
Command started - waithidden C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File “C:\Windows\Temp\script.ps1” (action:680664)
At 12:48:09 +0000 -
Encrypted Report posted successfully
At 12:48:13 +0000 - actionsite (http://bcgbigfix.den02.hosting.com:52311/cgi-bin/bfgather.exe/actionsite)
Command succeeded (Exit Code=0) waithidden C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File “C:\Windows\Temp\script.ps1” (action:680664)
At 12:48:13 +0000 -
ActionLogMessage: (action:680664) ending action
At 12:48:13 +0000 - mailboxsite (http://bcgbigfix.den02.hosting.com:52311/cgi-bin/bfgather.exe/mailboxsite544956121)
Not Relevant - Deploy PS Script (fixlet:680664)
At 12:49:24 +0000 -
Encrypted Report posted successfully

Sorry for replying late too… The agent log doesn’t show an error when running your script (exit code 0). It could be a user context problem as the script seems to work when run it manually on the system.

One option can be to run it in a context of a specific user with Administrative privilege, rather than local system context, you can try to use the override command as shown in the following example:

override waithidden
runas=localuser
asadmin=true
user=(local or domain user)
password=required
waithidden C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

For more info on the override command see https://developer.bigfix.com/action-script/reference/execution/override.html

Hi,
Thanks for the help. I tried to execute the PS Script using windows task scheduler and it worked.

1 Like