Unable to Manage IIS, Drivers or OS components from PowerShell

Issue

When trying to install drivers, or configure OS level components from PowerShell agents such as Intune MDM IntuneManagementExtension or AWS CodeDeploy these fail.

An example is trying to run pnputil.exe to install drivers from Intune MDM PowerShell reports that the executable is not found.

Resolution

These agents run as 32 bit, and the PowerShell must be run as 64 bit to manage operating system components.

Either call 64 bit PowerShell directly:

Start-Process "$env:WINDIR\sysnative\windowspowershell\v1.0\powershell.exe" -ArgumentList "pnputil.exe ..." 


Or have the script escalate itself to 64 bit:

if ($PSHOME -like "*SysWOW64*") {  
    # Restart this script under 64-bit Windows PowerShell.  
    #   (\SysNative\ redirects to \System32\ for 64-bit mode)  
    & (Join-Path ($PSHOME -replace "SysWOW64", "SysNative") powershell.exe) -File (Join-Path $PSScriptRoot $MyInvocation.MyCommand) @args  

    # Exit 32-bit script.  
    Exit  
}  

# 64 bit PowerShell
Created: 14th February 2018
Updated: 14th February 2018


© 2005-2018 Jamie Morrison