1

I am running a Powershell script from a bat file. These 2 files are placed on a network server and I am trying to run these on network server from my machine by accessing network server folder. I get following error:

CMD doesn't support UNC paths as current directories.

When I execute bat file , it tries to read script file from path

C:\Windows\System32

not from current directory which is set in bat file.

This script and bat file work fine when I run on my local machine.

I tried finding this on Google and possible solutions need to change some settings on network server which is not possible in my case.

What could be possible solution for this?
I am using PowerShell 2.0
Here is my bat file to run Powershell script

setlocal & pushd .

:getting current directory  
 cd /d %~dp0

Powershell.exe Set-ExecutionPolicy -ExecutionPolicy RemoteSigned  
Powershell.exe . '%CD%\Hotfix-Automation-Installer.ps1' crpt    
exit /B

1 Answer 1

1

It's like the message says: CMD doesn't support UNC paths as current directories, so you shouldn't use %CD% or . when you're working with UNC paths.

However, what's actually preventing your PowerShell script from being run is the single quotes around the path:

Powershell.exe . '%CD%\Hotfix-Automation-Installer.ps1' crpt

Single quotes are not valid quoting characters in CMD, so your script is actually trying to run the PowerShell script from a subfolder ' in the current directory. Which doesn't exist.

Change your script to this, and it should work just fine:

@echo off

powershell -ExecutionPolicy ByPass -File "%~dp0Hotfix-Automation-Installer.ps1" crpt
Sign up to request clarification or add additional context in comments.

1 Comment

"-ExecutionPolicy Bypass" will work, but I prefer "RemoteSigned" then adding specific UNC paths to the Intranet Zone, for running unsigned scripts from those locations. See option #2 found here: setspn.blogspot.com/2011/05/…

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.