1

I run this Powershell command in:

powershell -command "\\mydrive\apps\automation\install_this.bat" -Verb runas
  1. Std user, nonelevated Powershell
  2. Elevated Powershell
  3. Non-elevated Powershell ISE (with F5 "run script")

and it runs successfully but when I run that above line in Powershell ISE as Admin, it complains that it doesn't recognize the path.

PS C:\Windows\system32> powershell -command "\\mydrive\apps\automation\install_this.bat" -Verb runas

powershell : The system cannot find the path specified.
At line:1 char:1
+ powershell -command "\\mydrive\apps\automation\install_this.bat" - ...

So using F5 to "run script" is not the same as the way a one-liner powershell command runs. How do I get around that problem? It is most advantageous for me to get this to work in PS ISE elevated.. .

.

Here is my path:

C:\Users\dabbadoo>echo %PATH%
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Users\dabbadoo\AppData\Local\Microsoft\WindowsApps;

Here is my $env:PSModulePath -split ";"

C:\Users\dabbadoo\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules

And finally, here is the

$PROFILE | Get-Member -MemberType noteproperty | select name

Test-Path $Profile.AllUsersAllHosts
Test-Path $Profile.AllUsersCurrentHost
Test-Path $Profile.CurrentUserAllHosts
Test-Path $Profile.CurrentUserCurrentHost

output from PS ISE and PS ISE As Admin (they were same):

Name                  
----                  
AllUsersAllHosts      
AllUsersCurrentHost   
CurrentUserAllHosts   
CurrentUserCurrentHost
False
False
False
False
2
  • 1
    Please edit your question to include your PATH system variable. PowerShell ISE and a PowerShell command prompt use two entirely different profiles. You should also run $env:PSModulePath -split ";" and provide the output.
    – Ramhound
    Jan 12 at 20:09
  • 1
    $PROFILE | Get-Member -MemberType noteproperty | select name will output four PowerShell profiles. On each of those profiles run Test-Path $Profile.* where * is one of the names of the profiles. Since your issue is with PowerShell ISE this should be done within PowerShell ISE. As with the other information edit your question instead of submitting commentary.
    – Ramhound
    Jan 12 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.