Pages

Thursday, 2 February 2023

PS Install UNL

 #App Details

 $str_App = 'SHOPFO29120ENGC1 - Showpad for Outlook 2.9.12.0'
 $str_Packagecode = 'SHOPFO29120ENGC1'
 $str_InstallExe = 'Showpad_for_Outlook\Showpad.OutlookAddin-2.9.12.0.msi'
 $str_Arguments = 'REBOOT=REALLYSUPPRESS ALLUSERS=1 /QN'
 $str_DisplayName = 'Showpad for Outlook'
 
 #Prerequisite Install
 
 $str_InstallExe1 = 'Showpad_for_Outlook\Pre-Req\MicrosoftEdgeWebview2Setup.exe'
 $str_Arguments1 = '/silent /install'  
 $str_GUID = Get-ChildItem $str_UninstallKeys |
 ForEach-Object {Get-ItemProperty $_.pspath} |
 Where-Object {$_.Displayname -like "$str_DisplayName*"} |
 Select-Object PSPath, DisplayName, DisplayVersion
 $str_GUID = $str_GUID.pspath
 $str_GUID,$dump = $str_GUID.split('}')
 $dump,$str_GUID = $str_GUID.split('{')
 $str_GUID = "{$str_GUID}"
 
 #Uninstall
 $str_UninstallExe = "MSIEXEC.EXE"
 $str_Arguments = "/X $str_GUID MSIRESTARTMANAGERCONTROL=Disable REBOOT=ReallySuppress /QN"
  #Create Log folder
  $Str_ProgramData = $env:ProgramData
  $Str_LogFolder = "$Str_ProgramData\IntuneWin32Apps"
  if(!(Test-Path -Path $Str_LogFolder )){
  New-Item -ItemType directory -Path $Str_LogFolder
  }
  $str_LogFile = "$Str_LogFolder\IntuneWin32Apps.log"
  #Write App
  $str_LogEntry = "$(Get-Date) ; $str_App"
  Add-Content $str_LogFile $str_LogEntry
  #Write Version
  $str_LogEntry = "$(Get-Date) ; Version 1"
  Add-Content $str_LogFile $str_LogEntry
  #Write Start to Log File
  $str_LogEntry = "$(Get-Date) ; Install Starting"
  Add-Content $str_LogFile $str_LogEntry
  #Install Prerequisite
  $str_folder = split-path $script:MyInvocation.MyCommand.Path
  $str_InstallExe1 = """$str_folder\$str_InstallExe1"""
  $str_LogEntry = "$(Get-Date) ; Install Command: $str_InstallExe1 $str_Arguments1"
  Add-Content $str_LogFile $str_LogEntry
  $process = (start-process -filepath $str_InstallExe1 -argumentlist $str_Arguments1 -wait -PassThru)
  $exitcode = $process.ExitCode
  #Install App
  $str_folder = split-path $script:MyInvocation.MyCommand.Path
  $str_InstallExe = """$str_folder\$str_InstallExe"""
  $str_LogEntry = "$(Get-Date) ; Install Command: $str_InstallExe $str_Arguments"
  Add-Content $str_LogFile $str_LogEntry
  $process = (start-process -filepath $str_InstallExe -argumentlist $str_Arguments -wait -PassThru)
  $exitcode = $process.ExitCode
 
 #Check if another MSI install already in progress
  While($exitcode -eq '1618')
  {
       $str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode, MSI install in progress - wait 10 seconds and reinstall"
      Add-Content $str_LogFile $str_LogEntry
       #Wait patiently
      Start-Sleep -Seconds 10
      $process = (start-process -filepath $str_InstallExe1 -argumentlist $str_Arguments1 -wait -PassThru)
      $exitcode = $process.ExitCode
      #Update regCheck
      $process = (start-process -filepath $str_InstallExe -argumentlist $str_Arguments -wait -PassThru)
      $exitcode = $process.ExitCode
  }
  $str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode"
  Add-Content $str_LogFile $str_LogEntry
  #Install Completed
  $str_LogEntry = "$(Get-Date) ; Install Completed"
  Add-Content $str_LogFile $str_LogEntry
  #Close Log File
  $str_LogEntry = "-----------------------"
  Add-Content $str_LogFile $str_LogEntry

No comments:

Post a Comment

User based detection

function getloggedindetails () {     ##Find logged in username     $user = Get-WmiObject Win32_Process - Filter "Name='explorer...

Search This Blog