Running Built-in PowerShell Commands with Custom Fields
Current FileWave Windows clients are 64-bit, and Windows client-script Custom Fields can run in a 64-bit execution context. In the Custom Field editor, leave On Windows, run as 64-bit enabled when the script uses 64-bit PowerShell modules, 64-bit Windows components, or registry locations that are redirected for 32-bit processes.
Older Custom Fields may still be configured to run as 32-bit after an upgrade. FileWave preserves that setting so existing scripts continue to behave the same way. If an older field, or a field intentionally configured for 32-bit execution, needs to call 64-bit PowerShell, use one of the patterns below.
The example below lists the members of the local Administrators group. For a Custom Field running in the normal 64-bit context, run it directly as a PowerShell script:
Get-LocalGroupMember -Group 'Administrators' | Select Name

If the Custom Field is configured to run in a 32-bit context, some built-in cmdlets and modules may not be available. In that case, create the Custom Field as a BAT script and call the 64-bit executable explicitly. Use the Sysnative path when the command is launched from a 32-bit process on a 64-bit Windows device.
C:\Windows\sysnative\windowsPowerShell\v1.0\powershell.exe "Get-LocalGroupMember -Group 'Administrators' | Select Name"
exit 0

If an entire PowerShell script needs to relaunch itself from a 32-bit PowerShell process into 64-bit PowerShell, use the following wrapper:
#############################################################################
# If PowerShell is running the 32-bit version on a 64-bit machine, we
# need to force PowerShell to run in 64-bit mode.
#############################################################################
if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
# write-warning "Take me to 64-bit....."
if ($myInvocation.Line) {
&"$env:WINDIR\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile $myInvocation.Line
} else {
&"$env:WINDIR\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile -file "$($myInvocation.InvocationName)" $args
}
exit $lastexitcode
}
# Main script
# Uncomment the next line to prove that we are always in 64-bit
#[Environment]::Is64BitProcess
# Your 64-bit script here.
#############################################################################
# End
#############################################################################
No comments to display
No comments to display