SuckaMCs Posted February 24, 2014 Share Posted February 24, 2014 Hello, I am really new at scripting. I just need some advice on this script I am working on. I am not sure if i am doing this the best way. I have a ton of if statements already and i am getting a bit confused. It looks like it will be hard to troubleshoot if i had any problems with my script: Here is what I have so far before i explain to what i am trying to do: expandcollapse popup$osv = @OSVersion $ost = @OSArch ; First If Statement is to Check OS Version If $osv = "WIN_2008" Then ; Second If is to check OS archetechture If $ost = "x86" Then SetError(0) RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\","Install") ; Third If is to check .net Version If @error <> 0 Then MsgBox(0,"Info", ".NET v3.5 or higher is required!") Else MsgBox(0,"Info", ".NET v3.5 Is Not required!") EndIf ElseIf $ost = "x64" Then MsgBox(0, "", "64 Bit") EndIf Break(1) ElseIf $osv = "WIN_2003" or $osv = "WIN_2003R2" Then If $ost = "x86" Then SetError(0) RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\","Install") If @error <> 0 Then MsgBox(0,"Info", ".NET v3.5 or higher is required!") Else MsgBox(0,"Info", ".NET v3.5 Is Not required!") EndIf ElseIf $ost = "x64" Then MsgBox(0, "", "64 Bit") ElseIf $ost = "x64" Then MsgBox(0, "", "64 Bit") EndIf Break(1) Else MsgBox(0, "", "Not a Supported OS Version") EndIf #include <MsgBoxConstants.au3> Local $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine\", "PowerShellVersion") If $var <> "1.0" Then MsgBox(0, "", "Install PowerShel 2.0") Else MsgBox(0, "", "Uninstall Install PowerShell 1.0") EndIf So what i have so far is this. I want to first check to see what OS version it is. Because I want to deploy PowerShell 2.0 i only want this script to install on either Windows Server 2003, Windows Server 2003 R2 or Windows Server 2008. I also want to check weather or not the OS is x64 or x86, then i need it to if the OS has PowerShell 2.0 already, After it checks that, i need it to check if it has .net 3.5 SP1. After it checks for .net or powershell i will need it to do something. After it checks .net 3.5 i have a series of instal commands that i need to run. I hope this makes sense if anyone needs any other information please let me know. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 26, 2014 Moderators Share Posted February 26, 2014 As you're really searching on one item, the OS Version. I would do a switch. Determining whether it is x86 or x64 could be secondary. Something like this: Switch @OSVersion Case "WIN_2008" If @OSArch = "x86" Then RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\","Install") If @error <> 0 Then MsgBox(0,"Info", ".NET v3.5 or higher is required!") Else MsgBox(0,"Info", ".NET v3.5 Is Not required!") EndIf ElseIf @OSArch = "x64" Then MsgBox(0, "", "64 Bit") EndIf Case "WIN_2003","WIN_2003R2" If @OSArch = "x86" Then RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\","Install") If @error <> 0 Then MsgBox(0,"Info", ".NET v3.5 or higher is required!") Else MsgBox(0,"Info", ".NET v3.5 Is Not required!") EndIf ElseIf @OSArch = "x64" Then MsgBox(0, "", "64 Bit") EndIf Case Else MsgBox(0, "", "Not a Supported OS Version") EndSwitch "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
SuckaMCs Posted February 26, 2014 Author Share Posted February 26, 2014 (edited) Sorry for my late response but i wasn't able to access the site for a while for some reason. This is what i have now. Tell me what you think. expandcollapse popup$osv = @OSVersion $ost = @OSArch Local $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine\", "PowerShellVersion") Local $var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\","Version") Switch #OSVersion Case "WIN_2008" If $ost = "x86" Then If $var <> "1.0" Then $CMD = "C:\Install\dotnetfx35setup.exe /q /norestart" RunWait(@comspec & " /k " & $CMD) Sleep (360000) $CMD = "C:\Install\BITSx86.msu /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) $CMD = "C:\Install\WMF2k8x86.msu /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) $CMD = "Shutdown /R" RunWait(@comspec & " /c " & $CMD) Else $CMD = "ServerManagerCmd.exe -remove PowerShell -restart" RunWait(@comspec & " /k " & $CMD) Sleep (360000) $CMD = "C:\Install\dotnetfx35setup.exe /q /norestart" RunWait(@comspec & " /k " & $CMD) Sleep (360000) $CMD = "C:\Install\BITSx86.msu /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) $CMD = "C:\Install\WMF2k8x86.msu /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) M $CMD = "Shutdown /R" RunWait(@comspec & " /c " & $CMD) EndIf ElseIf $ost = "x64" Then MsgBox(0, "", "64 Bit Win 2008") If $var <> "1.0" Then $CMD = "C:\Install\dotnetfx35setup.exe /q /norestart" RunWait(@comspec & " /k " & $CMD) Sleep (360000) $CMD = "C:\Install\BITSx64.msu /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) $CMD = "C:\Install\WMF2k8x64.msu /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) $CMD = "Shutdown /R" RunWait(@comspec & " /c " & $CMD) Else $CMD = "ServerManagerCmd.exe -remove PowerShell -restart" RunWait(@comspec & " /k " & $CMD) Sleep (360000) $CMD = "C:\Install\dotnetfx35setup.exe /q /norestart" RunWait(@comspec & " /k " & $CMD) Sleep (360000) $CMD = "C:\Install\BITSx64.msu /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) $CMD = "C:\Install\WMF2k8x64.msu /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) $CMD = "Shutdown /R" RunWait(@comspec & " /c " & $CMD) EndIf EndIf Break(1) Case "WIN_2003","WIN2003R2" If $ost = "x86" Then If $var <> "1.0" Then $CMD = "C:\Install\dotnetfx35setup.exe /q /norestart" RunWait(@comspec & " /k " & $CMD) Sleep (360000) $CMD = "C:\Install\WMF2k3x86.exe /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) $CMD = "Shutdown /R" RunWait(@comspec & " /c " & $CMD) Else Sleep (360000) $CMD = "C:\Install\dotnetfx35setup.exe /q /norestart" RunWait(@comspec & " /k " & $CMD) Sleep (360000) M $CMD = "C:\Install\WMF2k3x86.exe /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) $CMD = "Shutdown /R" RunWait(@comspec & " /c " & $CMD) EndIf ElseIf $ost = "x64" Then If $var <> "1.0" Then $CMD = "C:\Install\dotnetfx35setup.exe /q /norestart" RunWait(@comspec & " /k " & $CMD) Sleep (360000) $CMD = "C:\Install\WMF2k3x64.exe /quiet /norestart" RunWait(@comspec & " /c " & $CMD) $CMD = "Shutdown /R" RunWait(@comspec & " /c " & $CMD) Else M Sleep (360000) $CMD = "C:\Install\dotnetfx35setup.exe /q /norestart" RunWait(@comspec & " /k " & $CMD) Sleep (360000) $CMD = "C:\Install\WMF2k3x86.exe /quiet /norestart" RunWait(@comspec & " /c " & $CMD) Sleep (360000) $CMD = "Shutdown /R" RunWait(@comspec & " /c " & $CMD) EndIf EndIf Break(1) Case Else MsgBox(0, "", "Not a Supported OS Version") EndSwitch Edited February 26, 2014 by SuckaMCs Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 26, 2014 Moderators Share Posted February 26, 2014 First off, the use of @OSVersion in the switch negates the need for this line: $osv = @OSVersion Also, I don't see any benefit to assigning @OSArch the variable name $ost, but that is personal preference. If $ost = "x86" Then ;vs If @OSArch = "x86" Then Lastly, as I don't see any point where you are disabling Break, not sure why you need this on lines 100 and 182. Unless you are doing it elsewhere in the script. Break(1) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
SuckaMCs Posted February 26, 2014 Author Share Posted February 26, 2014 I am new to this. So i can change that. I am still learning. Will make the changes you suggested. Other than those do you see something else that I should be fixing? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 26, 2014 Moderators Share Posted February 26, 2014 Nope, I think it looks good. And we were all on Day1 once, so no worries on being new. The most important thing in the beginning is - does the script do what you want it to? Polish can come later "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
SuckaMCs Posted February 26, 2014 Author Share Posted February 26, 2014 Thanks! I appreciate all your input. and yes the script actually works lol i was surprised. But again thanks for all your help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now