0

I'm trying to run a powershell script to search for a network drive for a certain file. In my testing, I've found that my script works perfectly fine, however the network drive I need to search require my Domain Admin logon.

I have

Start-Process powershell.exe -Credential "domain\adminusername" -NoNewWindow -ArgumentList "Start-Process powershell.exe -Verb runAs"

as the very first line of my script, but whenever I run the script I get this error:

Start-Process : This command cannot be run due to the error: The directory 
name is invalid.
At Path\to\script.ps1:1 char:1
+ Start-Process powershell.exe -Credential "domain\adminusername" -NoN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Start-Process], 
InvalidOperationException
+ FullyQualifiedErrorId : 
InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

What directory name is it talking about? If I move the script to the actual network drive, I still get the same error. How do you run a script as a different user?

1 Answer 1

1

You could use the net use command to gain access or the new-psdrive command instead. Another option would be to start-process a cmd prompt and use runas within it. Also, you may need to include the full path of powershell.exe or add it to the path variable. %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

Sign up to request clarification or add additional context in comments.

1 Comment

I have used New-PSDrive to map network drives with my admin credentials many times. Or you could always just do a Run As Different User on PowerShell when you first launch it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.