With the introduction of the Native PowerShell Support on the SMA several clients have had the necessity to run scripts using the PowerShell modules specific to the 64bit version using this new tool.
The SMA's agent being a 32bit application will target by default the 32bit version of PowerShell.
When running PowerShell on a KScript we are able to call the 64bit version by pointing our scripts to c:\windows\sysnative as described on KB Article: How To Use Windows 64bit 32bit Redirects (111236)
This KB article explains how to use the Native PowerShell Support to execute 64bit modules
This example is trying to pull the Administrator account information and it fails to do so:
Get-LocalUser -Name Administrator
This script will fail with a "Get-LocalUser is not recognized as the name of cmdlet..." error.
In order to tell the Native PowerShell script that we are trying to run part of the script using a 64bit module we must first, specify an alias so we can tell our script to look over on the 64bit side of PS:
Set-Alias Start-PowerShell64 "$env:windir\sysnative\WindowsPowerShell\v1.0\powershell.exe"
Start-PowerShell64 Get-LocalUser -Name Administrator
As a result we will get the proper information this time:
This brief example shows how to switch your script to point to the 64bit modules of PS using the Native PowerShell Support for the SMA's scripting module. If you are getting errors on your implementations and you get a similar error, refer back to the Microsoft's Documentation to make sure if you are trying to run a 32 or 64bit module, below is an example from their Get-LocalUser cmdlet documentation.
Note: The Microsoft.PowerShell.LocalAccounts module is not available in 32-bit PowerShell on a 64-bit system.
© 2024 Quest Software Inc. ALL RIGHTS RESERVED. Terms of Use Privacy Cookie Preference Center