0

Running the following VBA code opens PowerShell v1, and computes size remaining on DriveLetter C.

Sub RunPowershell()
    Set wShell = CreateObject("WScript.Shell")
    Set wShellResult = wShell.Exec("powershell (Get-Volume -DriveLetter C).SizeRemaining")
    ' Change to StdErr.ReadAll to read an error response
    MsgBox wShellResult.StdOut.ReadAll
End Sub

Is there a way to make VBA open PowerShell 7.3.6.0 when it's called in VBA?

Thanks in advance

I tried specifying the version number in the vba code

Sam
  • 5,424
  • 1
  • 18
  • 33
96ask
  • 1

1 Answers1

0

Newer Powershell is started with pwsh, rather than powershell. It is located in C:\Program Files\PowerShell\7, but it will probably work fine without a full path.

Sam
  • 5,424
  • 1
  • 18
  • 33