1

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?

6
  • It's a scripting language. Sometimes ugly is the only option. What exactly do you find ugly about the solution that you have?
    – EBGreen
    Oct 12, 2015 at 17:57
  • Well, I've come to realize that Receive-Job doesn't actually work so hot as I can't get access to the results from AccessNetworkShare() Oct 12, 2015 at 18:13
  • What exactly is AccessNetworkShare()?
    – EBGreen
    Oct 12, 2015 at 18:40
  • A listing of the files on a network share. The non-elevated user has rights to the share but the Local admin that runs an elevated command prompt doesn't Oct 12, 2015 at 19:02
  • So it is the name of an array? I'm just confused because that isn't valid powershell syntax.
    – EBGreen
    Oct 12, 2015 at 19:08

0

You must log in to answer this question.

Browse other questions tagged .