Share via


Converting VBS script to Powershell

Question

Monday, September 12, 2016 9:05 AM

I have a product called Manage Engine that has an agent that needs to be installed on all assets in our network. The product offers a VBS installer script but due to security requirements, I need to convert this into a Powershell script with code signing. I know how to code sign this script but am struggling to convert this VBS script into a working Powershell script. My challenge comes in with the version checking. Has anyone got any suggestions on how I can write this script to work

All replies (5)

Tuesday, September 13, 2016 3:33 AM ✅Answered

Hi Zefiris,

>> Has anyone got any suggestions on how I can write this script to work

I suppose the following link could provides some helps for converting:

https://technet.microsoft.com/en-us/library/ee221101.aspx

Besides, I'll give you a sample for the beginning:

https://social.technet.microsoft.com/Forums/windowsserver/en-US/87c3258c-a916-42c0-a621-ca9e81aed355/converting-vbs-to-powershell-logon-script-questions?forum=ITCG

Best regards,

Andy_Pan

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Monday, September 12, 2016 9:06 AM

'$Id$
'Script to  Install AssetExplorer Agent
'======================================

'To install agent with the share path given as argument
'===================================================================

On Error Resume Next

Set WSHShell = WScript.CreateObject("WScript.Shell")

'Get the arguments of the script
if(Wscript.Arguments.count>=1)then
    msiFile = WSCript.Arguments.Item(0)
    if(Wscript.Arguments.count>1)then
        latestAgentVersion = WSCript.Arguments.Item(1)
    end if
else
    Wscript.Echo "File name is not provided"
    Wscript.quit(0)
end if
'Wscript.Echo "msiFile - "&msiFile
'Wscript.Echo "latestAgentVersion - "&latestAgentVersion

const HKEY_LOCAL_MACHINE = &H80000002
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

is64BitOS = false
objReg.GetStringValue HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "PROCESSOR_ARCHITECTURE", osArch

if not isNULL(osArch) then
    pos=InStr(osArch,"64")
    if pos>0 Then
        is64BitOS = true
    End if
End if
if is64BitOS then
    objReg.GetStringValue HKEY_LOCAL_MACHINE, "SOFTWARE\Wow6432Node\ZOHO Corp\ManageEngine AssetExplorer\Agent\", "Version", currentVersion 
else
    objReg.GetStringValue HKEY_LOCAL_MACHINE, "SOFTWARE\ZOHO Corp\ManageEngine AssetExplorer\Agent\", "Version", currentVersion
end if

if(not isNull(latestAgentVersion) and latestAgentVersion <> "") and (not isNull(currentVersion) and currentVersion <> "")then
    latVer = Left(latestAgentVersion,InstrRev(latestAgentVersion,".")-1)
    currVer = Left(currentVersion,InstrRev(currentVersion,".")-1)
    latSP = Mid(latestAgentVersion,InstrRev(latestAgentVersion,".")+1)
    currSP = Mid(currentVersion,InstrRev(currentVersion,".")+1)
    if(Cdbl(currVer)>Cdbl(latVer) or (Cdbl(currVer)=Cdbl(latVer) and Cdbl(currSP)>=Cdbl(latSP) )) then
        'Wscript.Echo "already in latest version, so no need to download the agent again."
        Wscript.quit(0)
    end if
end if
'Wscript.Echo "Going to install."
Set WSHShell = WScript.CreateObject("WScript.Shell")
wshshell.Run "msiexec.exe /i """&msiFile&""" ENABLESILENT=yes REBOOT=ReallySuppress /qn",0,True

Monday, September 12, 2016 1:34 PM

You have not posted your PowerShell.  We can help and answer questions but this forum is not a consultant for converting scripts.

\(ツ)_/


Tuesday, September 13, 2016 10:00 AM

Hello JRV

I appreciate your <g class="gr_ gr_1173 gr-alert gr_gramm gr_run_anim Punctuation only-del replaceWithoutSep" data-gr-id="1173" id="1173"><g class="gr_ gr_1170 gr-alert gr_spell gr_disable_anim_appear ContextualSpelling" data-gr-id="1170" id="1170">feed-back</g>,</g> and am not looking to be spoon fed answers here. I really am here to learn as <g class="gr_ gr_1026 gr-alert gr_tiny gr_spell gr_run_anim ContextualSpelling multiReplace" data-gr-id="1026" id="1026">i</g> need to have this as a skill when implementing SCCM into our environment early next year. <g class="gr_ gr_1126 gr-alert gr_spell gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="1126" id="1126">Im</g> actually using this scripting as a stepping stone towards that.

Unfortunately, <g class="gr_ gr_1218 gr-alert gr_tiny gr_spell gr_run_anim ContextualSpelling multiReplace" data-gr-id="1218" id="1218">i</g> am legally not allowed to post any part of the code. Even as simple as it is. I cannot go against company policy and believe <g class="gr_ gr_1376 gr-alert gr_tiny gr_spell gr_run_anim ContextualSpelling multiReplace" data-gr-id="1376" id="1376">i</g> have asked. 

This point <g class="gr_ gr_1486 gr-alert gr_tiny gr_spell gr_run_anim ContextualSpelling multiReplace" data-gr-id="1486" id="1486">i</g> know <g class="gr_ gr_1487 gr-alert gr_tiny gr_spell gr_run_anim ContextualSpelling multiReplace" data-gr-id="1487" id="1487">i</g> have a working part to install the MSI agent by use of the build in switches for silent install. The version argument to control installations based on whether <g class="gr_ gr_1704 gr-alert gr_spell gr_run_anim ContextualSpelling" data-gr-id="1704" id="1704">its</g> presently installed, outdated or currently up to date is what's puzzling me.

I would appreciate any suggested reading or even a segment of code <g class="gr_ gr_1729 gr-alert gr_tiny gr_spell gr_run_anim ContextualSpelling multiReplace" data-gr-id="1729" id="1729">i</g> can play with to help me understand this better


Tuesday, September 13, 2016 10:01 AM

The post is completely  unreadable.  You have pasted raw html into the reply.

\(ツ)_/