Snapin (Template: Powershell) cannot load modules. Is this normal?
-
I’m writing a powershell script to use as a snapin. Works fine as user, works fine as admin, works fine as admin from a -noprofile, works fine from user as -noprofile. I get an error from the snapin when trying to load modules like Bitlocker, Microsoft.PowerShell.LocalAccounts, etc. This happens whether I use the module name, a command from within the module (get-localuser, get-bitlockervolume, etc.), or the full path to the module .psm1 file. I am using windows 10 1709.
The error I get is: the specified module XXXXXX was not loaded because no valid module was found in any module directory
Category info: ResourceUnavailable
FullyqualifiedErrorID: Modules_ModuleNotFound -
Start-Transcript -Path C:\$([Environment]::Is64BitProcess).txt "Is 64?" [Environment]::Is64BitProcess $pwd if ([Environment]::Is64BitProcess) { $a = Get-BitLockerVolume -MountPoint C: $a | Out-File C:\file.txt -append } else { $arguments = "-ExecutionPolicy Bypass -NoProfile -File temp.ps1 " start-process C:\WINDOWS\sysnative\WindowsPowerShell\v1.0\powershell.exe -ArgumentList $arguments -Wait -WorkingDirectory $pwd }
I know its not pretty, but its a proof of running 64 powershell. In essence, I need the 32bit to launch a 64bit version of powershell. Can’t just run powershell.exe because it goes still into x86.
-
Might have found the key:
ls C:\WINDOWS\sysnative\WindowsPowerShell\v1.0\Modules\bitlocker\bitlocker.psm1
ls C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\bitlocker\bitlocker.psm1Loading bitlocker normally uses system32. But SYSTEM on a 64 bit machine can’t find that path. Doing more testing now.
-
Hmmm, something funky.
PS > ls C:\WINDOWS\sysnative\WindowsPowerShell\v1.0\Modules\bitlocker\bitlocker.psm1
Directory: C:\WINDOWS\sysnative\WindowsPowerShell\v1.0\Modules\bitlocker
Mode LastWriteTime Length Name
-a---- 3/18/2017 2:59 PM 302052 bitlocker.psm1PS > Import-Module bitlocker
WARNING: The names of some imported commands from the module ‘bitlocker’ include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
PS > Get-BitLockerVolume -Mount C:
Unable to find type [Microsoft.BitLocker.Structures.BitLockerVolumeLockStatus].
At C:\WINDOWS\sysnative\WindowsPowerShell\v1.0\Modules\bitlocker\bitlocker.psm1:483 char:37- … -eq [uint32][Microsoft.BitLocker.Structures.BitLockerVolumeLockStatus …
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - CategoryInfo : InvalidOperation: (Microsoft.BitLo…olumeLockStatus:TypeName) [], RuntimeException
- FullyQualifiedErrorId : TypeNotFound
- … -eq [uint32][Microsoft.BitLocker.Structures.BitLockerVolumeLockStatus …
-
AH HAAAAAAA
"Is 64?" [Environment]::Is64BitProcess
Output is
Is 64? False
This means that the 32bit fog service is running powershell snapins as a 32 version of powershell. If you’ve used powershell recently, you’ve almost certainly been using the 64 bit… cause 32 bit sucks. Doesn’t run modules hardly ever, etc. this is the cause of my problems. All I need to do is get the 32 bit process to run the 64 bit powershell and I win!
Time to test.
-
Start-Transcript -Path C:\$([Environment]::Is64BitProcess).txt "Is 64?" [Environment]::Is64BitProcess $pwd if ([Environment]::Is64BitProcess) { $a = Get-BitLockerVolume -MountPoint C: $a | Out-File C:\file.txt -append } else { $arguments = "-ExecutionPolicy Bypass -NoProfile -File temp.ps1 " start-process C:\WINDOWS\sysnative\WindowsPowerShell\v1.0\powershell.exe -ArgumentList $arguments -Wait -WorkingDirectory $pwd }
I know its not pretty, but its a proof of running 64 powershell. In essence, I need the 32bit to launch a 64bit version of powershell. Can’t just run powershell.exe because it goes still into x86.