I\'ve got a PowerShell script that needs to be able to call another PS script from within the same directory with elevated credentials. Because the scripts need to be porta
So, I was able to figure out a solution that works as long as the brackets aren't empty []
.
Here's what I've got:
Start-Process Powershell -Verb runas -ArgumentList "-ExecutionPolicy","Bypass","-File","`"$(Get-Item -LiteralPath $PSScriptRoot\elevated.ps1)`""
Using this as the test path:
C:\Users\Administrator\Desktop\Test Folder\badname-!@#$%^_+-=.,{}`~[&]()
A path with empty brackets []
still doesn't work, but doesn't return an error. I'm assuming this means that it wasn't able to find a file in the expected path while interpreting the brackets as a wildcard still. Not sure if there's really anything that will fix that except maybe checking the path before running and throwing an error.