Skip to content

Instantly share code, notes, and snippets.

@fenneh
Created May 28, 2012 11:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fenneh/2818594 to your computer and use it in GitHub Desktop.
Save fenneh/2818594 to your computer and use it in GitHub Desktop.
Run a powershell script from UNC path
Powershell.exe -ExecutionPolicy Bypass -file \\my.domain.share\netlogon\Scripts\InstallPonies.ps1
@derekslenk
Copy link

This doesn't actually work FWIW

@fenneh
Copy link
Author

fenneh commented Jan 28, 2020

This doesn't actually work FWIW

It's 8 years old - pretty sure it used to :) Not had to do it for a long time.

@derekslenk
Copy link

I actually think it might more be AD GP than anything...it was a cluster.

@mrmattipants
Copy link

I understand that this is an older script, but since I stumbled upon it, while researching methods of Bypassing UNC Paths, I thought I'd leave a comment, as I'm sure others will follow.

One method, that I used to use often, in relation to Batch Scripts, was to utilize the PUSHD & POPD Commands.

Microsoft PUSHD Command:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/pushd

Microsoft POPD Command:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/popd

However, in relation to PowerShell, the Push-Location & Pop-Location Cmdlets, can be utilized.

Microsoft PowerShell Push-Location Cmdlet:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/push-location?view=powershell-7.3

Microsoft PowerShell Pop-Location Cmdlet:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/pop-location?view=powershell-7.3

Push-Location -Path $PSScriptRoot

Powershell.exe -ExecutionPolicy Bypass -File "$((Get-Location).path)\InstallPonies.ps"

Pop-Location

That said, if anyone comes along looking for a potential method of bypassing UNC Paths, in PowerShell, I'd experiment with this method, a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment