Pages

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

Monday, 15 August 2022

looping

$count = 0

$success = $null

# 1. This is to make sure the script is running. We can add this in network log file since the machine is not connected to network.

 $logfile_Temp = "C:\temp\CheckRunning.log"

 Add-Content $logfile_Temp -Value "This is to check the Gpupdate_DSRRedCmd.Ps1 is runnung or not"

 Do{
  try{

  # 1. Checking the VPN is connected to CISCO Anyconnect Mobility client.

 $NIC = Get-NetIPConfiguration | ? {$_.NetAdapter.status -eq "UP"} | Select-Object InterfaceDescription

if ($NIC -match "Cisco AnyConnect Secure Mobility Client Virtual Miniport Adapter for Windows")

 {

  Start-Sleep -Seconds 60

 $location = "\\housccm309\incoming$\Windows 10 Enterprise"

$comname = $env:computername

$logfile = "$location\$comname.log"

  Add-Content $logfile -Value "Machine is connected to Cisco AnyConnect Secure Mobility client "

 $success = $true

  Add-Content $logfile -Value "Executing Gpupdate /force wating time is 3 minutes"

  gpupdate /force

  Start-Sleep -Seconds 180

 Add-Content $logfile -Value "Gpupdate is executed successfully"

$oseditionwin10 = (Get-WmiObject -class Win32_OperatingSystem).Caption

Add-Content $logfile -Value "Machine is changed to $oseditionwin10"

 }

 ElseIF ($NIC -like "*Pulse*")

 {

 Start-Sleep -Seconds 60

 $location = "\\housccm309\incoming$\Windows 10 Enterprise"

$comname = $env:computername

$logfile = "$location\$comname.log"

Add-Content $logfile -Value "Machine is Connect to Pulse VPN"

  $success = $true

  Add-Content $logfile -Value "Executing Upupdate /force wating time is 3 minutes"

  gpupdate /force

  Start-Sleep -Seconds 180

 Add-Content $logfile -Value "Gpupdate is executed successfully"

 $oseditionwin10 = (Get-WmiObject -class Win32_OperatingSystem).Caption

Add-Content $logfile -Value "Machine is changed to $oseditionwin10"

    }

 Else

 {Add-Content $logfile_Temp -Value "Machine is waiting to join network"

}

 }

  catch {

    $location = "\\housccm309\incoming$\Windows 10 Enterprise"

$comname = $env:computername

$logfile = "$location\$comname.log"

Add-Content $logfile -Value "Error"

    }

  $count++

 }until($success)

Monday, 23 May 2022

MSIX Certificate

$expirationDate = {Get-Date}.Invoke().AddYears(5)

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

$thumbprint = (New-SelfSignedCertificate -notafter $expirationDate -Type CodeSigningCert -Subject "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" -FriendlyName "PowerToys Test Certificate" -KeyDescription "PowerToys Test Certificate" -KeyFriendlyName "PowerToys Test Key" -KeyUsage "DigitalSignature" -CertStoreLocation Cert:\LocalMachine\My).Thumbprint

Export-PfxCertificate -Cert cert:\LocalMachine\My\$thumbprint -FilePath PowerToys_TemporaryKey.pfx -Password $pass

Import-PfxCertificate -CertStoreLocation Cert:\LocalMachine\Root -FilePath PowerToys_TemporaryKey.pfx -Password $pass


Wednesday, 16 March 2022

Powershell script to to check te application version through app name

$driverversion = "7.5.7"

$version = (Get-WmiObject -Class Win32_Product | where Name -like "Sentinel System Driver Installer*" | select Version).version

If ($version -ge $driverversion){
Write-host "Already same or higher version of driver already installed in the machine"
}

Else {
Write-host "Application not found"
}

Thursday, 24 February 2022

VB Script to set a registry under HKCU through system context

 strComputer = "."

strRegPathSuffix = "\Desktop\Pavan"

strRegValueName = "EnableADAL"

intRegValueDec = "1"

strRegPathSuffix1 = "\Desktop\Pavan"

strRegValueName1 = "EnableADAL2"

intRegValueDec1 = "2"

Const HKEY_USERS = &H80000003

Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = ""

oReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys

    'wscript.echo subkey

    'We only want to do something if the subkey does not contain any of the following: .DEFAULT or S-1-5-18 or S-1-5-19 or S-1-5-20 or _Classes

    If NOT ((InStr(1,subkey,".DEFAULT",1) > 0) OR (InStr(1,subkey,"S-1-5-18",1) > 0) OR (InStr(1,subkey,"S-1-5-19",1) > 0) OR (InStr(1,subkey,"S-1-5-20",1) > 0) OR (InStr(1,subkey,"_Classes",1) > 0)) Then

    'Create desired registry key/value

    strKeyPath = subkey & strRegPathSuffix

    'wscript.echo strKeyPath

    oReg.CreateKey HKEY_USERS, strKeyPath

    oReg.SetStringValue HKEY_USERS, strKeyPath, strRegValueName, intRegValueDec

      oReg.SetDWORDValue HKEY_USERS, strKeyPath, strRegValueName1, intRegValueDec1

    End If

Next

Wednesday, 16 February 2022

Set user environmental variable through system contest

 # get the domain and username for the currently logged on user

 $domain, $userName = (Get-WmiObject -Class Win32_ComputerSystem).UserName -split '\\', 2

 # next, get the SID for that current user
 
 $user = [System.Security.Principal.NTAccount]::new($domain, $userName)
 
 $sid  = $user.Translate([System.Security.Principal.SecurityIdentifier]).Value
 
 # set the registry value for this user.
 Set-ItemProperty -Path "Registry::HKEY_USERS\$sid\Environment" -Name 'NAME2' -Value 'Value2' -Type String
 

Thursday, 10 February 2022

read and write permission through powershell

$folder_to_change = "C:\Temp\Aspen"
$acl = Get-Acl "$folder_to_change"
$ar = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Users", @("Read", "write"), "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($ar)
Set-Acl "$folder_to_change" $acl

Thursday, 20 January 2022

Installed application is higher than current version

$currentversion = "97.0.4692.90"

function Get-ApplicationVersion {
    $applicationName = "Google Chrome"
    $my_check = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, InstallDate | Where -Property DisplayName -Match $applicationName
    $versionNumber = $my_check.DisplayVersion
    if ($my_check) {
        $versionNumber
    }
    else {
        write-warning "Application not found"
    }
}
$version = Get-ApplicationVersion
If ($version -gt $currentversion) {
Write-host "Alredy higher version installed in the machine"
}
Else {
Write-host "Installing the current version"
}

Thursday, 6 January 2022

Copy File to user profile while installing through system contest

 For /F "tokens=2* delims= " %%u IN ('Reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /V ProfilesDirectory') DO Set ProfilesDir=%%v

Set ProfilesDir=%profilesDir:%%SystemDrive%%=%\%ProfilesDir:~14,100%

For /F "tokens=*" %%d IN ('Dir /ad /b "%ProfilesDir%"') DO (

If /I NOT "%%d" == "ALL USERS" (

xcopy "%~dp0FIlezilla" "%ProfilesDir%\%%d\appdata\Roaming\FileZIlla" /y /e))

Tuesday, 28 December 2021

Replace file extension

ls C:\Temp\Tesingname\*.* | ? { !$_.PSIsContainer   -and   $_.extension -eq '.txt' } |   ren -NewName { "$($_.BaseName)_$(get-date -format "yyyyMMdd_HHmmss")$($_.extension) "  }  
ls C:\Temp\Tesingname\*.* | ? { !$_.PSIsContainer   -and   $_.extension -eq '.log' } |   ren -NewName { "$($_.BaseName)_$(get-date -format "HHmmss")$($_.extension) "  }  


Thursday, 7 October 2021

Remove only path variable through powershell

 $path = [System.Environment]::GetEnvironmentVariable(

    'PATH',
    'User' # For user variable
    #'Machine' for system variable
)
 
$path = ($path.Split(';') | Where-Object { $_ -ne 'var1' }) -join ';'
 
$path = ($path.Split(';') | Where-Object { $_ -ne 'var2' }) -join ';'
# Set it
[System.Environment]::SetEnvironmentVariable(
    'PATH',
    $path,
    'User' # For user variable
    #'Machine' for system variable
)

Test

   $AppList = Get-InstalledApplication -Name 'Air Explorer'                 ForEach ($App in $AppList)         {         If($App.Uni...

Search This Blog