I'm trying to run a script that requires elevation to set certain registry values to allow CredSSP on local and remote computers and, during this script, I need to access a network share as a non-elevated account.
My initial thought was to try
Invoke-Command -ScriptBlock { [IO.Directory]::GetFiles($networkShare) } -Credential $cred
where $cred is a non-elevated users' credentials. Unfortunately, that doesn't work due to this bug.
The workaround given is to use -ComputerName localhost
but that requires that my local machine be set up for PS Remote, which I don't want to do.
The best workaround I've found is to use
$foo = Start-Job -Credential $cred -ScriptBlock { [IO.Directory]::GetFiles($networkShare) }
$out = Receive-Job $foo
That works but it's just so ugly...can anyone help me find a better solution?