Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a batch script which I am trying to open a file (powershell script on a network location). If I put the path as a local c:\test.ps1 it works fine but I cant seem to get it to work with the network file structure.

@echo off 
(set/p adminuser=Enter Your Admin Account: ) 
runas /user:%userdomain%\%adminuser% "powershell "\\Server\share$\IT Support\Test\Test Share\test.ps1"" 

Any ideas?

Thanks.

share|improve this question
    
checked path is accessible to user account? –  nakchak May 9 '13 at 14:30
    
Certainly is... Not sure if its because the file path has spaces in but just cant get it to work sadly. –  user2299515 May 9 '13 at 14:34
    
what happens if you try powershell -executionpolicy bypass "\\Server\share$\IT Support\Test\Test Share\test.ps1" ? –  nakchak May 9 '13 at 14:39
    
Are you running this from a workstation or a server? What errors or messages do you get? –  Matt Williamson May 9 '13 at 14:44
    
Still wont run, just closes down the command prompt. If I put in a local short path it works fine so it def the path thats the issue althrough the path is perfectly correct. –  user2299515 May 9 '13 at 14:44

1 Answer 1

up vote 0 down vote accepted

Try this:

@echo off 
(set/p adminuser=Enter Your Admin Account: ) 
runas /user:%userdomain%\%adminuser% "powershell -noexit & '\\Server\share$\IT Support\Test\Test Share\test.ps1'"
share|improve this answer
    
Matt you are a bloody legend. wracked my brains over that. Thanks you dude. –  user2299515 May 9 '13 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.