Jump to content

PowerShell Deployment Scripts 1.0.4

   (2 reviews)

1 Screenshot

About This File

I used the stock PowerShell 2.0 update script, and modified it for PowerShell 3, 4, and 5. I attempted to cover pre-requisites checks to prevent installing on systems with incompatible applications or operating systems. The scripts will check if the KB is reported as installed after the update completes to determine status. This means that the script will report the update was successful even if a reboot is still needed.

The attached .ZIP has 3 scripts, one for each version, in a single XML bundle. To import the Scripts, select Tools -> Import -> XML Expansion. After import the scripts should appear in the "__Examples" folder. This pairs nicely with the PowerShell Version Roles at https://www.labtechgeek.com/files/file/13-powershell-version-roles/


What's New in Version 1.0.4   See changelog

Released

Exchange Server should be detected correctly in the PS3.0 script.
Updated capitalization for "PowerShell" in each script.

  • Like 3
  • Thanks 3

User Feedback

Recommended Comments

So I'm trying to run the PowerShell 5 deploy on "Microsoft Windows Server 2008 R2 Enterprise x64" OS Version "6.1.7601 Service Pack 1" .

The WMF page says SP1 is good.  https://docs.microsoft.com/en-us/powershell/wmf/overview 

The script is checking for SP1 in step 4, but its not finding it and going to the fail label from step 5.

 

The SQL Check is "SELECT version FROM computers WHERE computerid=%computerid%" Contains "Service Pack 1"

Does this need to be %os% instead?

 

Link to comment
Share on other sites

On 8/30/2018 at 2:38 PM, Mrjoshua said:

The SQL Check is "SELECT version FROM computers WHERE computerid=%computerid%" Contains "Service Pack 1"

Does this need to be %os% instead?

I'm going with "No". Computers.version contains the "Service Pack x" string, so that is the right place to be checking for it.

Computers_OS_or_Version.png

Try running the following query:    

SELECT version FROM computers WHERE computerid=XXX

with XXX being the correct computer id.

Or it might be helpful to run the script using the debugger to learn more about what is going on. (After that step executes, the internal variable %sqlresult% should have the value returned by the query, you can see if the service pack is listed).

Link to comment
Share on other sites

Ty @DarrenWhite99 for this amazing script, i edited the bachfile to deal with multiple location, i ll try to automate the bath file with automate!

::---------------------------------------------------------------------------------
::  Script      : Install ConnectWise Automate Agent
::  Version     : 0.1
::  Written by  : Chuck Fowler
::---------------------------------------------------------------------------------
:: Token will Expire on 8/19/2021 2:41:40 AM UTC

@ECHO OFF

ipconfig    | find /i "10.101.1." > NUL
IF %ERRORLEVEL% == 0 GOTO DataCenter

ipconfig    | find /i "192.168.1." > NUL
IF %ERRORLEVEL% == 0 GOTO ST-Jerome

ipconfig    | find /i "192.168.2." > NUL
IF %ERRORLEVEL% == 0 GOTO Terrebonne

ipconfig    | find /i "192.168.5." > NUL
IF %ERRORLEVEL% == 0 GOTO ST-Hippolyte

ipconfig    | find /i "192.168.7." > NUL
IF %ERRORLEVEL% == 0 GOTO Bois-Leger-Concept

ipconfig    | find /i "192.168.8." > NUL
IF %ERRORLEVEL% == 0 GOTO RollandGodard

ECHO Ip adres conflict
GOTO END

:DataCenter
%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -Command "Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/CUSTUM_LOCATION_JUST_TO_BE_SAFE/master/Automate-Module.psm1'); Install-Automate -Server 'SECRET.AUTOMATE.SERVER' -LocationID 470 -Token 'HIDDEN' -Transcript"
GOTO END

:ST-Jerome
%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -Command "Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/CUSTUM_LOCATION_JUST_TO_BE_SAFE/master/Automate-Module.psm1'); Install-Automate -Server 'SECRET.AUTOMATE.SERVER' -LocationID 22 -Token 'HIDDEN' -Transcript"
GOTO END

:Terrebonne
%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -Command "Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/CUSTUM_LOCATION_JUST_TO_BE_SAFE/master/Automate-Module.psm1'); Install-Automate -Server 'SECRET.AUTOMATE.SERVER' -LocationID 112 -Token 'HIDDEN' -Transcript"
GOTO END

:ST-Hippolyte
%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -Command "Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/CUSTUM_LOCATION_JUST_TO_BE_SAFE/master/Automate-Module.psm1'); Install-Automate -Server 'SECRET.AUTOMATE.SERVER' -LocationID 116 -Token 'HIDDEN' -Transcript"
GOTO END

:Bois-Leger-Concept
%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -Command "Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/CUSTUM_LOCATION_JUST_TO_BE_SAFE/master/Automate-Module.psm1'); Install-Automate -Server 'SECRET.AUTOMATE.SERVER' -LocationID 114 -Token 'HIDDEN' -Transcript"
GOTO END

:RollandGodard
%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -Command "Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/CUSTUM_LOCATION_JUST_TO_BE_SAFE/master/Automate-Module.psm1'); Install-Automate -Server 'SECRET.AUTOMATE.SERVER' -LocationID 113 -Token 'HIDDEN' -Transcript"
GOTO END

:END

 

Edited by nicecube
Link to comment
Share on other sites

On 8/20/2020 at 7:59 AM, nicecube said:

Ty @DarrenWhite99 for this amazing script, i edited the batchfile to deal with multiple location, I'll try to automate the batch file with automate!


@ECHO OFF
::---------------------------------------------------------------------------------
::  Script      : Install ConnectWise Automate Agent
::  Version     : 0.1
::  Written by  : Chuck Fowler
::---------------------------------------------------------------------------------
:: Token will Expire on 8/19/2021 2:41:40 AM UTC

ipconfig    | find /i "10.101.1." > NUL && GOTO DataCenter
ipconfig    | find /i "192.168.1." > NUL && GOTO ST-Jerome
ipconfig    | find /i "192.168.2." > NUL && GOTO Terrebonne
ipconfig    | findstr /i /r /c:"Gateway .* 192\.168\.5\." > NUL && GOTO ST-Hippolyte
ipconfig    | findstr /i /r /c:"Gateway .* 192\.168\.7\." > NUL && GOTO Bois-Leger-Concept
ipconfig    | findstr /i /r /c:"Gateway .* 192\.168\.8\." > NUL && GOTO RollandGodard

ECHO IP address unrecognized
GOTO END

 

Glad it helped @nicecube! I owe the entirety of that script to @Braingears though.

I did tweak it a bit, for some possible improvements.  You can use the "COMMAND1 && COMMAND2" syntax and COMMAND2 will only execute if COMMAND1 ended successfully.  So FIND.exe can be used with && to directly jump instead of testing ERRORLEVEL.  Also, findstr.exe can use limited regular expressions, so you can do a more complex match like specifying the Default Gateway you are targeting, not just a matching IP.  (Typically to match that without typing the entire line you would see something like: ipconfig | find /i "Gateway" | find /i "192.168.5." > NUL )

 

  • Like 1
Link to comment
Share on other sites

Hello Darren,

I ran this script 93 times and it worked perfectly all 93 times. Thank you.

If I wanted this script to update to PowerShell 5.1 instead of 5.0, would I only need to edit lines  37 and 39 with the 5.1 file name, then 43 and 44 with the new direct download link to PowerShell 5.1 on 32 bit?

For 64 bit it would be lines 47, 49, and 51 with the 64 bit 5.1 file names, then lines 55, 56, and 59 with the 64 bit 5.1 direct download link?

Further down the script, I would then update references to 5.0 with 5.1?

Line 104 would be the PowerShell 5.1 requirements?

-Mike

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...