Pages

Sunday, 19 November 2023

MSIX Codesigning Certificate

 $pass = ConvertTo-SecureString -String "12345" -Force -AsPlainText

$thumbprint = (New-SelfSignedCertificate -Type Custom -Subject "CN=Microsoft Corporation" -KeyUsage DigitalSignature -FriendlyName “VLC Applicaton Certificate" -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")).Thumbprint

Export-PfxCertificate -Cert Cert:\CurrentUser\My\$thumbprint -FilePath "c:\temp\VLCmediaplayer.pfx" -Password $pass

Import-PfxCertificate -CertStoreLocation Cert:\LocalMachine\Root -FilePath "c:\temp\VLCmediaplayer.pfx" -Password $pass

Monday, 5 June 2023

Import TASK scheduler from xml file

 $taskname = "Remove MSTeams (Public version)"

$taskxmlpath = "Path of the xml file"

$taskusername = "SYSTEM"

$taskexists = Get-ScheduledTask -TaskName $taskname -ErrorAction SilentlyContinue

If ($taskexists.TaskName -eq "$taskname") {

Write-host "$taskname -already exists"

}

Else {


Register-ScheduledTask -xml (Get-Content "$taskxmlpath" | Out-String) -TaskName "$taskname" -User $taskusername -Force


write-host "$tasname -registered"

}


PASADT to create form restart requirement

 $proceed = 'RestartLater'

$noClickCounter = 0


while ($noClickCounter -lt 3) {

$noClickCounter++


$proceed = Show-InstallationPrompt -Title 'Restart Prompt' -Message "OHS Application Installation Completed. Click 'RestartNow' To Reboot the Machine.Click 'RestartLater' to Snooze the Restart for 1 hour. Deferral $noClickCounter" -ButtonRightText 'Restartnow' -ButtonLeftText 'RestartLater'


if ($proceed -eq 'RestartNow') {

Restart-Computer -Force

break

}


if ($noClickCounter -eq 3) {

$proceed = Show-InstallationPrompt -Title 'Restart Prompt' -Message 'OHS Application Installation Completed. Maximum Restart Diferrals Completed.Restart your Machine Now' -ButtonMiddleText 'Restart'

 Restart-Computer -Force

}

else {

Sleep -Seconds 3600

}

}

Thursday, 25 May 2023

PSADT to create Form sample

    $proceed = 'No'

   $noClickCounter = 0


    while ($proceed -ne 'Yes') {

    $proceed = Show-DialogBox -Title 'Installation Notice' -Text 'Application is Installed, would you like to restart the machine?' -Buttons $([System.Windows.Forms.MessageBoxButtons]::YesNo) -DefaultButton 'First' -Icon 'Exclamation' -Topmost $true


    if ($proceed -eq 'No') {

        $noClickCounter++


        if ($noClickCounter -eq 3) {

            $proceed = Show-DialogBox -Title 'Installation Notice' -Text 'Application is Installed, would you like to restart the machine?' -Buttons $([System.Windows.Forms.MessageBoxButtons]::OK) -DefaultButton 'First' -Icon 'Exclamation' -Topmost $true

        Restart-Computer -Force

        }

        else {

            Sleep -Seconds 30

        }

    }

    elseif ($proceed -eq 'Yes') {

        Restart-Computer -Force

    }

}


Tuesday, 7 March 2023

Wallpaer PS script

function Set-Wallpaper {
    param (

        [string]$Path,

        [ValidateSet('Tile', 'Center', 'Stretch', 'Fill', 'Fit', 'Span')]

        [string]$Style = 'Fill'

    )
    begin {
        try {
            Add-Type @"
                using System;
                using System.Runtime.InteropServices;
                using Microsoft.Win32;
                namespace Wallpaper
                {  public enum Style : int
                    {  Tile, Center, Stretch, Fill, Fit, Span, NoChange

                    }
                    public class Setter

                    {
                        public const int SetDesktopWallpaper = 20;

                        public const int UpdateIniFile = 0x01;

                        public const int SendWinIniChange = 0x02;

                        [DllImport( "user32.dll", SetLastError = true, CharSet = CharSet.Auto )]

                        private static extern int SystemParametersInfo ( int uAction, int uParam, string lpvParam, int fuWinIni );

                        public static void SetWallpaper ( string path, Wallpaper.Style style )

                        {

                            SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );

                            RegistryKey key = Registry.CurrentUser.OpenSubKey( "Control Panel\\Desktop", true );

                            switch( style )

                            {

                                case Style.Tile :

                                key.SetValue( @"WallpaperStyle", "0" ) ;

                                key.SetValue( @"TileWallpaper", "1" ) ;

                                break;

                                case Style.Center :

                                key.SetValue( @"WallpaperStyle", "0" ) ;

                                key.SetValue( @"TileWallpaper", "0" ) ;

                                break;

                                case Style.Stretch :

                                key.SetValue( @"WallpaperStyle", "2" ) ;

                                key.SetValue( @"TileWallpaper", "0" ) ;

                                break;

                                case Style.Fill :

                                key.SetValue( @"WallpaperStyle", "10" ) ;

                                key.SetValue( @"TileWallpaper", "0" ) ;

                                break;

                                case Style.Fit :

                                key.SetValue( @"WallpaperStyle", "6" ) ;

                                key.SetValue( @"TileWallpaper", "0" ) ;

                                break;

                                case Style.Span :

                                key.SetValue( @"WallpaperStyle", "22" ) ;

                                key.SetValue( @"TileWallpaper", "0" ) ;

                                break;

                                case Style.NoChange :

                                break;

                            }

                            key.Close();

                        }

                    }

                }

"@

        } catch {}



        $StyleNum = @{

            Tile = 0

            Center = 1

            Stretch = 2

            Fill = 3

            Fit = 4

            Span = 5

        }

    }
    process {

        [Wallpaper.Setter]::SetWallpaper($Path, $StyleNum[$Style])
        sleep -s 5

        [Wallpaper.Setter]::SetWallpaper($Path, $StyleNum[$Style])

    }

}
#App Details

$str_App = 'INWPC000001ENGC1 - Inspire Wallpaper Update'

$str_PackageCode = 'INWPC000001ENGC1'

#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



# Setting up Wallaper

$StrLAppdata = $env:LOCALAPPDATA

$str_folder = split-path $script:MyInvocation.MyCommand.Path

$Str_Wallpaper = "$StrLAppdata\Unilever"

if(!(Test-Path -Path $Str_Wallpaper )){

  New-Item -ItemType directory -Path $Str_Wallpaper

}

$Source_path=Join-Path -Path $str_folder -ChildPath "\C19"

$Des_Path=Join-path -Path $StrLAppdata -ChildPath "\Unilever\"

Copy-item $Source_Path -Destination $Des_Path -Force -Recurse -Verbose

#Checking the screen resolution

Add-Type -AssemblyName System.Windows.Forms

$Resolution= "{0}x{1}" -f [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width,[System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height

write-host $Resolution

#Write Log

$str_LogEntry = "$(Get-Date) ; ScreenResolution is: $Resolution"

Add-Content $str_LogFile $str_LogEntry

#Setting wallpaper based on screen resolution

if ($Resolution  -eq '1920x1080')

{ start-process (Set-WallPaper -Path "$StrLAppdata\Unilever\C19\Wallpaper1.jpg" -Style Fill)

  $str_LogEntry = "$(Get-Date) ; Wallpaper Set: $StrLAppdata\Unilever\C19\Wallpaper1.jpg"

  Add-Content $str_LogFile $str_LogEntry

}



elseif ($Resolution  -eq '2133x1600')

{ start-process (Set-WallPaper -Path "$StrLAppdata\Unilever\C19\Wallpaper2.jpg" -Style Fill)

  $str_LogEntry = "$(Get-Date) ; Wallpaper Set: $StrLAppdata\Unilever\C19\Wallpaper2.jpg"

  Add-Content $str_LogFile $str_LogEntry

}



elseif ($Resolution  -eq '4000x2250')

{ start-process (Set-WallPaper -Path "$StrLAppdata\Unilever\C19\Wallpaper3.jpg" -Style Fill)

  $str_LogEntry = "$(Get-Date) ; Wallpaper Set: $StrLAppdata\Unilever\C19\Wallpaper3.jpg"

  Add-Content $str_LogFile $str_LogEntry

}



else

{ start-process (Set-WallPaper -Path "$StrLAppdata\Unilever\C19\Wallpaper2.jpg" -Style Fill)

  $str_LogEntry = "$(Get-Date) ; Default Wallpaper Set: $StrLAppdata\Unilever\C19\Wallpaper2.jpg"

  Add-Content $str_LogFile $str_LogEntry

}

if (!(Test-Path -Path "HKCU:\SOFTWARE\Unilever\Packages")){

New-Item -Path "HKCU:\SOFTWARE\Unilever\Packages" -Force

}
New-ItemProperty "HKCU:\SOFTWARE\Unilever\Packages" -Name "INWPC000001ENGC1_Installed" -Value "Intune_WP_Installed" -PropertyType "String" -Force | Out-Null

#Close Log File

$str_LogEntry = "-----------------------"

Add-Content $str_LogFile $str_LogEntry 

Saturday, 25 February 2023

Process

 # Define an array of process names

 $processNames = @("process_name_1", "process_name_2", "process_name_3")

 # Loop through the process names and check if they are running
 
 foreach ($processName in $processNames) {
     if (Get-Process $processName -ErrorAction SilentlyContinue) {
 
         Write-Host "$processName is running."
         # If the process is running, close it
 
         Stop-Process -Name $processName -Force
 
         Write-Host "$processName has been closed."
 
     }
 
     else {
 
         Write-Host "$processName is not running."
 
     }
 
 }
 
 

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

Archi Install script- PS

 #AUARC002020ENGC1 - Autodesk AutoCAD Architecture 2020 - English (8.2.47.0)


$errorActionPreference = "SilentlyContinue"

If ($ENV:PROCESSOR_ARCHITEW6432 -eq "AMD64") {

    Try {

        &"$ENV:WINDIR\SysNative\WindowsPowershell\v1.0\PowerShell.exe" -ExecutionPolicy bypass -NoProfile -File $PSCOMMANDPATH

    }

    Catch {

        Throw "Failed to start $PSCOMMANDPATH"

    }

    Exit

}

#App Details

$str_App = 'AUARC002020ENGC1 - Autodesk AutoCAD Architecture 2020 - English (8.2.47.0)'

$str_PackageCode = 'AUARC002020ENGC1'

#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 - Create Scheduled Task to Install 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

#Create Temp Install Folder

$TempInstallFolder = -join ("c:\programdata\", $str_PackageCode, "_Install")

if(!(Test-Path -Path $TempInstallFolder )){

  New-Item -ItemType directory -Path $TempInstallFolder

}

New-Item -Path $TempInstallFolder -ItemType Directory -Force -Confirm:$false | out-null

$str_LogEntry = "$(Get-Date) ; Folder created: $TempInstallFolder"

Add-Content $str_LogFile $str_LogEntry

#Copy Img Folder

$currentfolder = split-path $script:MyInvocation.MyCommand.Path



Copy-Item -path "$currentfolder\Img" -Destination $TempInstallFolder -Recurse -Force

$str_LogEntry = "$(Get-Date) ; Img folder copied to $TempInstallFolder"

Add-Content $str_LogFile $str_LogEntry

#Copy Licensing Script

$currentfolder = split-path $script:MyInvocation.MyCommand.Path

Copy-Item -path "$currentfolder\Set_autodesknlm_license_server.vbs" -Destination $TempInstallFolder -Recurse -Force

$str_LogEntry = "$(Get-Date) ; Set_autodesknlm_license_server.vbs file copied to $TempInstallFolder"

Add-Content $str_LogFile $str_LogEntry

#Create Install Script

$install =

@'

$errorActionPreference = "SilentlyContinue"



$str_App = 'AUARC002020ENGC1 - Autodesk AutoCAD Architecture 2020 - English (8.2.47.0)'

$str_PackageCode = 'AUARC002020ENGC1'

$str_LogFile = "C:\ProgramData\IntuneWin32Apps\IntuneWin32Apps.log"

#Write App

$str_LogEntry = "$(Get-Date) ; $str_App - Install"

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

#Uninstall Previous Versions

$Array = @(

    [pscustomobject]@{MSIGUID='{28B89EEF-0004-0000-3102-CF3F3A09B77D}';APPNAME='AutoCAD Architecture 2017'}

    [pscustomobject]@{MSIGUID='{28B89EEF-0004-0000-0102-CF3F3A09B77D}';APPNAME='AutoCAD Architecture 2017 Core'}

    [pscustomobject]@{MSIGUID='{28B89EEF-0004-0000-4102-CF3F3A09B77D}';APPNAME='AutoCAD Architecture 2017 Shared'}

    [pscustomobject]@{MSIGUID='{28B89EEF-0001-0000-0102-CF3F3A09B77D}';APPNAME='AutoCAD 2017'}

    [pscustomobject]@{MSIGUID='{28B89EEF-0001-0409-1102-CF3F3A09B77D}';APPNAME='AutoCAD 2017 Language Pack - English'}

    [pscustomobject]@{MSIGUID='{28B89EEF-0004-0000-5102-CF3F3A09B77D}';APPNAME='ACA & MEP 2017 Object Enabler'}

    [pscustomobject]@{MSIGUID='{28B89EEF-0004-0409-1102-CF3F3A09B77D}';APPNAME='AutoCAD Architecture 2017 Language Core - English'}

    [pscustomobject]@{MSIGUID='{28B89EEF-0004-0409-2102-CF3F3A09B77D}';APPNAME='AutoCAD Architecture 2017 - English'}

    [pscustomobject]@{MSIGUID='{28B89EEF-0004-0409-4102-CF3F3A09B77D}';APPNAME='AutoCAD Architecture 2017 Language Shared - English'}

)

#Loop Through Array

For ($num = 0 ; $num -le $Array.count-1 ; $num++) {

    $AppName = $Array[$num].APPNAME

    $MSIGUID = $Array[$num].MSIGUID

    $UninstallExe = 'MsiExec.exe'

    $Arguments = "/X $MSIGUID REBOOT=ReallySuppress MSIRESTARTMANAGERCONTROL=Disable /QN"

       $process = (start-process -filepath $UninstallExe -argumentlist $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

        #Update regCheck

        $process = (start-process -filepath $UninstallExe -argumentlist $Arguments -wait -PassThru)

        $exitcode = $process.ExitCode

    }

    If($exitcode -eq '1605') {

        $str_LogEntry = "$(Get-Date) ; $AppName not installed"

        Add-Content $str_LogFile $str_LogEntry

    } Else{

        $str_LogEntry = "$(Get-Date) ; Uninstalling $AppName"

        Add-Content $str_LogFile $str_LogEntry

        $str_LogEntry = "$(Get-Date) ; Uninstall Command: $UninstallExe $Arguments"

        Add-Content $str_LogFile $str_LogEntry

                $str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode"

        Add-Content $str_LogFile $str_LogEntry

    }

}

#Delete old install folder if it exists

$Str_INSTALLDIR = "c:\Program Files\Autodesk\AutoCAD 2017"

If(Test-Path -Path $Str_INSTALLDIR ){

    Remove-Item $Str_INSTALLDIR -Recurse -Force

    $str_LogEntry = "$(Get-Date) ; INSTALLDIR Deleted - $Str_INSTALLDIR"

    Add-Content $str_LogFile $str_LogEntry

}

#Install App

$str_InstallCommand = 'c:\programdata\AUARC002020ENGC1_Install\Img\Setup.exe'

$str_Arguments = "/w /q /l ""c:\programdata\AUARC002020ENGC1_Install\Img\AUARC002020ENGC1.ini"" /language en-us"



$str_LogEntry = "$(Get-Date) ; Installing Autodesk AutoCAD Architecture 2020"

Add-Content $str_LogFile $str_LogEntry

$str_LogEntry = "$(Get-Date) ; Install Command: $str_InstallCommand $str_Arguments"

Add-Content $str_LogFile $str_LogEntry

$process = (start-process -filepath $str_InstallCommand -argumentlist $str_Arguments -wait -PassThru)

$exitcode_app = $process.ExitCode

Check if another MSI install already in progress

While($exitcode_app -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



    #Update regCheck

    $process = (start-process -filepath $str_InstallCommand -argumentlist $str_Arguments -wait -PassThru)

    $exitcode_app = $process.ExitCode

}



$str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode_app"

Add-Content $str_LogFile $str_LogEntry

#Configure the licensing server

$str_InstallCommand = """C:\ProgramData\AUARC002020ENGC1_Install\Set_autodesknlm_license_server.vbs"""

$str_Arguments = "RUN"

$str_LogEntry = "$(Get-Date) ; Configure the Licensing Server"

Add-Content $str_LogFile $str_LogEntry

$str_LogEntry = "$(Get-Date) ; $str_InstallCommand $str_Arguments"

Add-Content $str_LogFile $str_LogEntry

$process = (start-process -filepath $str_InstallCommand -argumentlist $str_Arguments -wait -PassThru)

$exitcode_license = $process.ExitCode

$str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode_license"

Add-Content $str_LogFile $str_LogEntry

$str_InstallCommand = """c:\Program Files (x86)\Common Files\Autodesk Shared\AdskLicensing\Current\helper\AdskLicensingInstHelper.exe"""

$str_Arguments = 'change --pk "185L1" --pv "2020.0.0.F" --lm "NETWORK" --ls """" --lt """"'                                

$str_LogEntry = "$(Get-Date) ; $str_InstallCommand $str_Arguments"

Add-Content $str_LogFile $str_LogEntry

$process = start-process -filepath $str_InstallCommand -argumentlist $str_Arguments -wait -PassThru

$exitcode_helper = $process.ExitCode

$str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode_helper"

Add-Content $str_LogFile $str_LogEntry

#Delete Scheduled Task

If((($exitcode_app -eq '0') -OR ($exitcode_app -eq '3010')) -AND ($exitcode_license -eq '0') -AND ($exitcode_helper -eq '0'))

{

    #Install Successful

    $str_LogEntry = "$(Get-Date) ; Install Successful"

    Add-Content $str_LogFile $str_LogEntry

    $str_LogEntry = "$(Get-Date) ; Scheduled Task Deleted: Install $str_PackageCode"

    Add-Content $str_LogFile $str_LogEntry

    #Delete Desktop Shortcut

    $Str_PUBLIC = $env:PUBLIC

    Remove-Item -Path "$Str_PUBLIC\Desktop\AutoCAD Architecture 2020*.lnk" -Force -Recurse

    $str_LogEntry = "$(Get-Date) ; Desktop Shortcut deleted"

    Add-Content $str_LogFile $str_LogEntry

    #Delete Startmenu shortcut

    Remove-Item -Path "C:\programdata\Microsoft\Windows\Start Menu\Programs\Autodesk\Uninstall Tool.lnk" -Force

    $str_LogEntry = "$(Get-Date) ; Startmenu shortcut deleted - C:\programdata\Microsoft\Windows\Start Menu\Programs\Autodesk\Uninstall Tool.lnk"

    Add-Content $str_LogFile $str_LogEntry

    #Deleting Temp Install Folder

    $TempInstallFolder = -join ("c:\programdata\", $str_PackageCode, "_Install")

    Remove-Item "$TempInstallFolder\Img" -Recurse -Force

    $str_LogEntry = "$(Get-Date) ; Temp Install Folder Deleted: $TempInstallFolder\Img"

    Add-Content $str_LogFile $str_LogEntry

    #Deleting Detection File

    $TempInstallFolder = -join ("c:\programdata\", $str_PackageCode, "_Install")

    Remove-Item "$TempInstallFolder\$str_PackageCode - Detection.txt" -Recurse -Force



    $str_LogEntry = "$(Get-Date) ; Detection File Deleted: $TempInstallFolder\$str_PackageCode - Detection.txt"

    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

    Unregister-ScheduledTask -TaskName "Install $str_PackageCode" -Confirm:$false

    Start-Sleep -Seconds 5

}Else{

    #Install Completed

    $str_LogEntry = "$(Get-Date) ; Install Failed - will try again on next reboot"

    Add-Content $str_LogFile $str_LogEntry

    #Close Log File

    $str_LogEntry = "-----------------------"

    Add-Content $str_LogFile $str_LogEntry

}

'@

$InstallFile = "$TempInstallFolder\$str_PackageCode - Install.ps1"

Out-File -FilePath $InstallFile -Encoding unicode -Force -InputObject $install -Confirm:$false

$str_LogEntry = "$(Get-Date) ; Install Script created: $InstallFile"

Add-Content $str_LogFile $str_LogEntry

#Create Scheduled Task

Stop-ScheduledTask -TaskName "Install $str_PackageCode"

Start-Sleep -Seconds 5

Unregister-ScheduledTask -TaskName "Install $str_PackageCode" -Confirm:$false

Start-Sleep -Seconds 5

$action = New-ScheduledTaskAction -Execute 'PowerShell.exe' -Argument "-ex bypass -file ""$InstallFile"""

$STPrin = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount  -RunLevel Highest

$STTrigger = New-ScheduledTaskTrigger -AtLogon

$STSet = New-ScheduledTaskSettingsSet -RunOnlyIfNetworkAvailable -AllowStartIfOnBatteries

Register-ScheduledTask -Action $action -TaskName "Install $str_PackageCode" -Description "Install $str_PackageCode" -Principal $STPrin -Settings $STSet -Trigger $STTrigger

Start-Sleep -Seconds 5

$str_LogEntry = "$(Get-Date) ; Scheduled Task created: Install $str_PackageCode"

Add-Content $str_LogFile $str_LogEntry

#Create Detection File

$DetectionFile = "$TempInstallFolder\$str_PackageCode - Detection.txt"

New-Item $DetectionFile

$str_LogEntry = "$(Get-Date) ; Creating Detection File: $DetectionFile"

Add-Content $str_LogFile $str_LogEntry

#Close Log File

$str_LogEntry = "-----------------------"

Add-Content $str_LogFile $str_LogEntry

Monday, 23 January 2023

Uninstall PS1 UNL

$errorActionPreference = "SilentlyContinue"

If ($ENV:PROCESSOR_ARCHITEW6432 -eq "AMD64") {

    Try {

        &"$ENV:WINDIR\SysNative\WindowsPowershell\v1.0\PowerShell.exe" -ExecutionPolicy bypass -NoProfile -File $PSCOMMANDPATH
    }

    Catch {
        Throw "Failed to start $PSCOMMANDPATH"
 }
    Exit
}

#App Details

$str_App = 'JAWSR202121ENGC1 - Freedom Scientific JAWS 2021'

$str_PackageCode = 'JAWSR202121ENGC1'

$str_UninstallExe = 'MsiExec.exe'

$str_UninstallExe1 = "c:\Programdata\Package Cache\{4de0dac0-e7b5-4fbd-8370-86df7920062d}\JAWS setup package.exe"

$str_UninstallExe2 = "C:\Program Files\Freedom Scientific\FSReader\3.0\UninstallFSReader.exe"

$str_Token1 = $args[0]

$str_Token2 = $args[1]

#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_Uninstall.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

If (test-path $str_UninstallExe1){

 $str_UninstallExe1 = "c:\Programdata\Package Cache\{4de0dac0-e7b5-4fbd-8370-86df7920062d}\JAWS setup package.exe"

 $Arguments = "/uninstall /quiet"

 $AppName = "Freedom Scientific JAWS 2021.2103.174.400"

$str_LogEntry = "$(Get-Date) ; Uninstalling $AppName"

Add-Content $str_LogFile $str_LogEntry

$str_LogEntry = "$(Get-Date) ; Install Command: $str_UninstallExe1 $Arguments"

Add-Content $str_LogFile $str_LogEntry

$process = (start-process -filepath $str_UninstallExe1 -argumentlist $Arguments -wait -PassThru)

$exitcode = $process.ExitCode

$str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode"

Add-Content $str_LogFile $str_LogEntry

}

Else {

$str_LogEntry = "$(Get-Date) ; Freedom Scientific JAWS 2021.2103.174.400 not installed"

Add-Content $str_LogFile $str_LogEntry

}

If (test-path $str_UninstallExe2){

 $str_UninstallExe2 = "C:\Program Files\Freedom Scientific\FSReader\3.0\UninstallFSReader.exe"

 $Arguments = "/S"

 $AppName = "Freedom Scientific FSReader 3.5.210.0"

$str_LogEntry = "$(Get-Date) ; Uninstalling $AppName"

Add-Content $str_LogFile $str_LogEntry

$str_LogEntry = "$(Get-Date) ; Install Command: $str_UninstallExe2 $Arguments"

Add-Content $str_LogFile $str_LogEntry

$process = (start-process -filepath $str_UninstallExe2 -argumentlist $Arguments -wait -PassThru)

$exitcode = $process.ExitCode

$str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode"

Add-Content $str_LogFile $str_LogEntry

}

Else {

$str_LogEntry = "$(Get-Date) ; Freedom Scientific FSReader 3.5.210.0 not installed"

Add-Content $str_LogFile $str_LogEntry

}

$Array = @(

    [pscustomobject]@{MSIGUID='{BD25E96E-17B1-487B-8342-0406697FC48D}';APPNAME='Freedom Scientific Telemetry 3.3.6.0'}

    [pscustomobject]@{MSIGUID='{92F55251-4B8C-4159-98FE-B6744E925E0D}';APPNAME='RDP Support 23.3.4.0'}

    [pscustomobject]@{MSIGUID='{C9FFAB1B-D20C-46CC-B72E-F1A2038A005C}';APPNAME='Freedom Scientific USB Camera Driver 14.0.40.101'}

    [pscustomobject]@{MSIGUID='{C7389029-7C1B-4FF2-8A81-F1136ABAA94D}';APPNAME='Keyboard Manager 3.3.6.400'}

    [pscustomobject]@{MSIGUID='{11C9F4EE-775E-469C-A983-8A2935B0B71D}';APPNAME='Freedom Scientific Authorization 7.3.2.0'}

    [pscustomobject]@{MSIGUID='{481435FF-97AC-11E6-8DDB-64006A5729E1}';APPNAME='Freedom Scientific Fusion Interface 2.100.7.0'}

    [pscustomobject]@{MSIGUID='{4466ADE6-D352-4BFF-904C-B7948BA89982}';APPNAME='Freedom Scientific Touch Server 3.0.3001.0'}

    [pscustomobject]@{MSIGUID='{136F1D08-5DD2-4B52-8B2E-FA70AFE505A5}';APPNAME='Freedom Scientific Error Reporting 8.3.5.0'}

    [pscustomobject]@{MSIGUID='{1CCBF2EE-E481-4A55-B7AF-EE729078B5EE}';APPNAME='FSOcrTombstone 14.0.700'}

    [pscustomobject]@{MSIGUID='{194B7DA0-20B8-4E8B-9AFB-4D893187A9A9}';APPNAME='Freedom Scientific Ocr 19.3.3.0'}

    [pscustomobject]@{MSIGUID='{E63CDB0E-C508-44CA-AE57-8733ACA0AEDC}';APPNAME='Freedom Scientific OmniPage 20 18.0.10.0'}

    [pscustomobject]@{MSIGUID='{AE1E7553-752E-4D04-9695-EE1FB83C54AE}';APPNAME='Freedom Scientific JAWS Training Table Of Contents DAISY Files 22.0.58.0'}    

    [pscustomobject]@{MSIGUID='{92BFB73A-4A8F-42DD-AFC9-16A91A2902D3}';APPNAME='Freedom Scientific WOW64 Proxy 21.0.3000.0'}

    [pscustomobject]@{MSIGUID='{B5B7D6B7-111D-4A6A-824D-EB4631F5C722}';APPNAME='Freedom Scientific HookManager 3.0.3001.0'}

    [pscustomobject]@{MSIGUID='{6C654742-DA97-4B78-B1CA-A0859A9B1243}';APPNAME='Freedom Scientific UIAHooks 22.3.8.0'}

    [pscustomobject]@{MSIGUID='{D1B43B83-02A9-4D36-BBC4-ED34532D728D}';APPNAME='Freedom Scientific Synth 22.3.8.0'}

    [pscustomobject]@{MSIGUID='{AF6A5953-FE5F-451C-BD86-D0EB3F76A6E0}';APPNAME='Freedom Scientific Elevation 22.3.8.0'}

    [pscustomobject]@{MSIGUID='{FAEE61D3-2A5E-4F7F-926F-77AAC08CE4DD}';APPNAME='Sentinel System Driver Installer 7.5.0 7.5.0'}

    [pscustomobject]@{MSIGUID='{A334FFCA-53ED-4C84-9A60-48CA885382AB}';APPNAME='Freedom Scientific Utilities 22.3.11.0'}

    [pscustomobject]@{MSIGUID='{38464CAB-C140-4C39-BE4C-C68D062130DA}';APPNAME='Freedom Scientific Video Accessibility 12.6.352.0'}

    [pscustomobject]@{MSIGUID='{F4DA19E5-A560-4313-8623-3493DCE3C681}';APPNAME='Freedom Scientific Synthesizer Eloquence 6.1.8'}

    [pscustomobject]@{MSIGUID='{72596573-EEDF-4173-BF45-71E8FA0067DD}';APPNAME='Freedom Scientific Ocr 19.3.3.0'}

    [pscustomobject]@{MSIGUID='{9CBFFF67-CB9F-4D77-9093-1B456381EC9D}';APPNAME='FSOcrTombstone 14.0.700'}

    )

#Loop Through Array

For ($num = 0 ; $num -le $Array.count-1 ; $num++) {

    $AppName = $Array[$num].APPNAME

    $MSIGUID = $Array[$num].MSIGUID

    $UninstallExe = 'MsiExec.exe'

    $Arguments = "/X $MSIGUID REBOOT=ReallySuppress MSIRESTARTMANAGERCONTROL=Disable /QN"

    $process = (start-process -filepath $UninstallExe -argumentlist $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

        #Update regCheck

        $process = (start-process -filepath $UninstallExe -argumentlist $Arguments -wait -PassThru)

        $exitcode = $process.ExitCode

    }

    If($exitcode -eq '1605') {

        $str_LogEntry = "$(Get-Date) ; $AppName not installed"

        Add-Content $str_LogFile $str_LogEntry

    } Else{

        $str_LogEntry = "$(Get-Date) ; Uninstalling $AppName"

        Add-Content $str_LogFile $str_LogEntry

        $str_LogEntry = "$(Get-Date) ; Uninstall Command: $UninstallExe $Arguments"

        Add-Content $str_LogFile $str_LogEntry

                $str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode"

        Add-Content $str_LogFile $str_LogEntry

    }

}

#--------------------------------

#Remove User from Uninstall Group

Import-Module SaC.MSGraph-AuthToken

# Get package

$UninstallGroup = "Managed W10 App - $str_PackageCode - Uninstall"

$URI = "https://graph.microsoft.com/v1.0/groups?`$filter=startswith(displayName,`'$($UninstallGroup)`')"

# Get AAD Auth token

$Request = Get-BearerToken $str_Token1 $str_Token2

$token = $Request.access_token

$headers = @{ "Authorization" = "Bearer " + $token }

# Get UPN

$username = Get-WmiObject Win32_Process -Filter "Name='explorer.exe'" | ForEach-Object { $_.GetOwner() } | Select-Object -Unique -Expand User

$userUPN = ($username + '@unilever.com').ToLower()

$str_LogEntry = "$(Get-Date) ; User UPN $userUPN"

Add-Content $str_LogFile $str_LogEntry

# Get user ID via the users UPN

$myProfile = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/users/$($userUPN)/" -Headers $headers -Method GET -ContentType "application/json"

$myId = $myProfile.id

# Create body of request and convert to json

$body = @{ "@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/$($myId)" } | ConvertTo-Json

# Get group ID

$groupMetaData = Invoke-RestMethod -Uri $URI -Headers $headers -Method GET -ContentType "application/json"

$groupId = $groupMetaData.value[0].id

# Remove User from Group

$response = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/groups/$($groupId)/members/$($myId)/`$ref" -Headers $headers -Method DELETE -Body $body -ContentType "application/json"

# Log File

$str_LogEntry = "$(Get-Date) ; User removed from $UninstallGroup"

Add-Content $str_LogFile $str_LogEntry

#--------------------------------

#Delete Uninstall Detection Key

Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Unilever\IntuneWin32Apps' -Name "$str_PackageCode Uninstall Group" -Force

$str_LogEntry = "$(Get-Date) ; HKLM:\SOFTWARE\Unilever\IntuneWin32Apps\$str_PackageCode Uninstall Group Reg Key Deleted"

Add-Content $str_LogFile $str_LogEntry

#Uninstall Completed

$str_LogEntry = "$(Get-Date) ; Uninstall Completed"

Add-Content $str_LogFile $str_LogEntry

#Close Log File

$str_LogEntry = "-----------------------"

Add-Content $str_LogFile $str_LogEntry

User based detection

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

Search This Blog