I have cross-posted my reply to microsoft.public.windows.powershell where
there is likely to be more expertise in powershell. You might also want to
check here:
http://www.microsoft.com/technet/scriptcenter/topics/winpsh/convert/default.mspx
Here is a powershell script that accomplishes exactly what your vbscript
does:
# not much to do here... ;-)
Your script certainly defines some functions - but it does not cause those
functions to be called, so the net result is as if the functions were not
defined in the first place.
That said:
Powershell has no equivalent to the dim statement, other than perhaps the
equivalent of doing this in vbscript: [variable = ""]. It also has no need
of the file system object or the shell object. It scopes its variables
differently.
/Al
> '
> *************************************************************************
> ' Declare variables with the Dim, Public or the Private statement
> '
> *************************************************************************
> Dim WshShell, FSO
> Dim gTmpPath
>
>
> '
> *************************************************************************
> ' Establish values for each of the declared variables - i believe each
> of these are global variables
> '
> *************************************************************************
> Set WshShell = CreateObject("WScript.Shell")
> Set FSO = CreateObject("Scripting.FileSystemObject")
>
>
> '
> *************************************************************************
> ' This function provides a temp path. To be used by the ExecuteCmd
> function.
> '
> *************************************************************************
> Function GetTempPath
> GetTempPath = WshShell.ExpandEnvironmentStrings("%TEMP%") & "\"
> End Function
>
> '
> *************************************************************************
> ' Executes a command and returns the text output
> '
> *************************************************************************
> Function doCmd(cmd)
>
> Dim exeOutput ' Create variable, local to this function
> Dim sCmd ' Create variable, local to this function
> Dim outFile, outFilename ' Create variables, local to this
> function
>
> outFilename = gTmpPath & FSO.GetTempName ' Establish values for
> variables
>
> sCmd = "%COMSPEC% /D /c " & cmd & " > " & outFilename
> 'Wscript.Echo sCmd
> exeOutput = WshShell.Run(sCmd, 0, True)
> 'Wscript.Echo exeOutput
> Set outFile = FSO.OpenTextFile(outFilename)
> doCmd = outFile.ReadAll
> outFile.Close
> FSO.DeleteFile(outFilename)
>
> End Function
On Feb 22, 6:58 pm, "Al Dunbar" <aland...@hotmail.com> wrote:
> "rickkar" <rmkarc...@gmail.com> wrote in message
>
> news:38e5c6b7-1fb9-4834...@a12g2000yqm.googlegroups.com...
>
> > Hi ---
>
> > I'm looking for help to convert the VBScript below to Powershell --
> > I'd appreciate any help
>
> I have cross-posted my reply to microsoft.public.windows.powershell where
> there is likely to be more expertise in powershell. You might also want to
> check here:
>
> http://www.microsoft.com/technet/scriptcenter/topics/winpsh/convert/d...
> > End Function- Hide quoted text -
>
Dim cmdOut ' Create variable
Dim path ' Create variable
path = Wscript.ScriptFullName
path = Left(path, inStrRev(path, "\"))
'Wscript.Echo path
gTmpPath = GetTempPath() ' Create variable
cmdOut = doCmd( """" & path & "PreReqChecker\omchecks.exe"" 2008_CORE
3 0" )
'Wscript.Echo cmdOut
'
*************************************************************************
' The WScript object is the root object of the Windows Script Host
(Wsh) object model hierarchy.
'
*************************************************************************
'get os name
Dim regEx, Match, Matches ' Create variables
Dim lineRex, lineMatches
Dim astr, found
Set regEx = New RegExp ' Create a regular expression
Set lineRex = New RegExp ' Create a regular expression
regEx.Pattern = ".*\n" ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity
regEx.Global = True ' Set global applicability
lineRex.Pattern = "Status=\s*(\d+)"
Set Matches = regEx.Execute(cmdOut) ' Execute search
For Each Match in Matches ' Iterate Matches collection
Set lineMatches = lineRex.Execute(Match.value)
if lineMatches.count > 0 then
'Wscript.Echo lineMatches(0).SubMatches(0)
astr = lineMatches(0).SubMatches(0)
found = Cint(astr)
exit For
end if
Next
Dim sCmd, exeOutput ' Create a regular expression
Dim title, jCmd, jPath, jOut ' Create a regular expression
title = " Dell PowerVault Modular Disk Storage Manager"
jCmd = path & "ia\jre\bin\java"
jPath = path & "setup_java"
jOut = " > """ & gTmpPath & "MD3000i_setup.txt"" 2>&1"
if ( found = 3 ) then ' 3 is the core return value
sCmd = "%COMSPEC% /C "" """& jCmd & """ -cp """ & jPath & """ setup
""" & path & "\""" & jOut & """"
else
sCmd = "%COMSPEC% /C """ & path & "setup.exe"""
end if
===> you're welcome. I hope one of the regulars from the powershell
newsgroup will respond, as I lack the necessary powershell experience to say
much more than what I have already said.
That said, however, and possibly contrary to what is said about it on the
technet site, I do not think a mechanical translation from one language to
the other is necessarily the way to go here. Much of the detail of how we
script is determined by the nature of the scripting language, and there are
very significant differences between vbscript and powershell. I would think
a better result would be had by learning to code in powershell and
re-working this as if you were starting from scratch. I suspect it would
require less effort on your part to do so than on someone else's part to
cobble together a working version without the benefit of having your
environment to run it in.
/Al