1

I have to convert this to Powershell:

On Error Resume Next

strComputer = "."

Set WshShell = CreateObject("WScript.Shell")
Set oEnv = WshShell.Environment("Process")
sScriptPath = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - (Len(WScript.ScriptName) + 1))


    WshShell.run "MsiExec.exe /i " & Chr(34) & sScriptPath & "\Install.msi" & chr(34) & " Transforms=" & chr(34) & sScriptPath & "\Install.mst" & chr(34),0 , True

WScript.Quit(0)

What I know:

On Error Resume Next

is default in Powershell

Set WshShell = CreateObject("WScript.Shell")

is something like

$WshShell = New-Object -ComObject Wscript.Shell -Strict

Can I then do

$oEnv = $WshShell.Environment("Process")

What WScrip.ScriptFullName is the full path or the current script?

How do I call that WshShell.run command in Powershell?

3
  • Tada: technet.microsoft.com/en-us/library/ee221101.aspx Commented Jul 29, 2016 at 8:27
  • Thanks man, however the Download this conversion guide leads to an unavailable page. Can I access it other ways? Commented Jul 29, 2016 at 8:49
  • Just read it online: the table of contents is in the left pane. Commented Jul 29, 2016 at 8:59

1 Answer 1

1

In PowerShell you'd normally just use

$env:VARIABLE

instead of something convoluted like

$oEnv = (New-Object -COM WScript.Shell).Environment('Process')
$oEnv.Item('VARIABLE')

If you need to get a variable specifically from the "User", "Machine", or "Process" environment you'd use something like this:

[Environment]::GetEnvironmentVariable('VARIABLE', 'User')

The equivalent to WScript.ScriptFullName is $MyInvocation.MyCommand.Path (or $PSScriptRoot in more recent versions).

Instead of the Run method you'd use the call operator (&).

Sign up to request clarification or add additional context in comments.

Comments

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.