This all feels like a bug, but I hope someone can prove me wrong.
PS version: 5.1.17763.592
I'm launching a powershell script from a UNC path with the "-file" and "-NoExit" parameter. This is done from a VB.net application. The VB.Net .exe is run as admin, the Powershell session also then starts as admin.
Dim script_path As String = "-NoExit -ExecutionPolicy RemoteSigned -file \\PATH\Test.ps1"
Process.Start("Powershell", script_path)
This all launches fine, but for some unknown reason this Powershell instance do not behave the same way as if I were to run powershell as admin directly. For example:
Some registry information cant be found or is returned differently.
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Measure-Object
Returns 116 in "-file" instance, 36 in standard instance.
cd "HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client\Software Distribution\Execution History\"
Returns not found in -file instance, but it do exist. I have found a few registry keys like this one.
This instance has 13 fewer modules avaliable (Get-Module -ListAvailable | Measure-Object
), some cmdlets cant be run, for example Get-LocalUser
.
It kind of feels like im remoting to a completely different computer when I'm not.
Same computer, same user, both powershell run as admin.
I've tried:
- Launch from a local directory (Not UNC)
- Remove -NoExit param.
- Launching cmd as admin manually then
powershell.exe -NoExit -ExecutionPolicy RemoteSigned -file \\UNC\Test.ps1
(This do not have the same limited instance)
I would understand if this mode was somewhat limited and modules need to be imported manually, but it doesnt explain why registry information is returned differently.