Archive for October, 2020

PowerShell: Remove Google Chrome (any version)

The following PowerShell script will allow you to remove any installed version of Google Chrome.

Function UninstallChrome() {
    $app = get-wmiobject Win32_Product | Where-Object {$_.Name -eq "Google Chrome"}
    $removeChrome = $app.IdentifyingNumber msiexec /x
    $removeChrome /q
 }
 
# If chrome is running then close the process and uninstall it
 If (Get-Process chrome -ErrorAction SilentlyContinue) {
    # Chrome is running
    # Stop chrome process
    Stop-Process -Name chrome -Force

    # Now uninstall chrome
    UninstallChrome
 } Else {
     # Chrome is not running…
     # Uninstall chrome
     UninstallChrome
 } 

, , , , ,

Leave a comment

PowerShell: Create a Repetitive Scheduled Task for Shadow Copy

The following article describes how to create a scheduled task that creates Shadow Copies in Windows 10. The scheduled task will run daily and at 8:00AM and every 4 hours for a total of 8 hours.

Here are is the PowerShell code that does it:

# Create a scheduled task
$taskAction = New-ScheduledTaskAction -Execute "wmic.exe" -Argument "shadowcopy call create Volume=C:\"
 
# Set how many times the task runs daily and its frequencey
$taskTrigger = New-ScheduledTaskTrigger -Daily -At 8am
$taskTrigger.Repetition = $(New-ScheduledTaskTrigger -Once -At "08:00" -RepetitionDuration "8:00" -RepetitionInterval "04:00").Repetition
 
# Task owner is SYSTEM account and task runs wether user is logged on or not
$taskPrincipal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
 
# Task settings to wake device, to run hidden and to allow to run on battery
$taskSettings = New-ScheduledTaskSettingsSet -WakeToRun -Hidden -AllowStartIfOnBatteries
 
# Setup scheduled task object
$scheduledTask = New-ScheduledTask -Principal $taskPrincipal -Action $taskAction -Trigger $taskTrigger -Settings $taskSettings
 
# Register scheduled task based on setup information gathered from $scheduledTask variable
Register-ScheduledTask "Daily Shadow Copy" -InputObject $scheduledTask

Next the screenshots of the result when the code is executed.

Task general properties. Note that it runs with the SYSTEM account.
We use WMIC to create a volume shadow copy for C:\
Here’s the trigger/schedule information for the task

Leave a comment