Bypassing windows during processes

I am almost finished with my script that gets rid of certain windows updates and hides them but after an unistall it asks if you want to restart I cannot seem to get my

$wshell = New-Object -ComObject;
$wshell.AppActivate(‘Windows Update Standalone Installer’)
Sleep 2

could I put two keys one to tab and one to enter? maybe an IF statement to say if true for unistalling then hit these two keys? I am newer to this so I don’t have advanced skills for powershell. Thanks!

If you are using SendKeys as a solution, it is most likely the wrong solution. In vbScript forums, I used to continually talk folks out of using it because there is no way to ensure the script is doing what it’s supposed to. You’re sending commands blindly to the screen and assuming that the Window you expect opened and is active when you are sending commands.

With that said, there is a programmatic way to manage hiding windows updates. Take a look at this article:

I used to create the below that hides the annoying Windows 7 language packs in my labs:

Function Get-WindowsUpdate {
    Process {
        try {
            Write-Verbose "Getting Windows Update"
            $Session = New-Object -ComObject Microsoft.Update.Session            
            $Searcher = $Session.CreateUpdateSearcher()            
            $Criteria = "IsInstalled=0 and DeploymentAction='Installation' or IsPresent=1 and DeploymentAction='Uninstallation' or IsInstalled=1 and DeploymentAction='Installation' and RebootRequired=1 or IsInstalled=0 and DeploymentAction='Uninstallation' and RebootRequired=1"           
            $SearchResult = $Searcher.Search($Criteria)           
        } catch {
            Write-Warning -Message "Failed to query Windows Update because $($_.Exception.Message)"
Function Show-WindowsUpdate {
    Get-WindowsUpdate |
    Select Title,isHidden,
        @{l='Size (MB)';e={'{0:N2}' -f ($_.MaxDownloadSize/1MB)}},
        @{l='Published';e={$_.LastDeploymentChangeTime}} |
    Sort -Property Published

Function Set-WindowsHiddenUpdate {
    Process {
        $Update | ForEach-Object -Process {
            if (($_.pstypenames)[0] -eq 'System.__ComObject#{c1c2f21a-d2f4-4902-b5c6-8a081c19a890}') {
                try {
                    $_.isHidden = $Hide
                    Write-Verbose -Message "Dealing with update $($_.Title)"
                } catch {
                    Write-Warning -Message "Failed to perform action because $($_.Exception.Message)"
            } else {
                Write-Warning -Message "Ignoring object submitted"

$updates = Get-WindowsUpdate
$updates | Where{$_.Title -like "*language*" -and $_.IsHidden -eq $false} | Set-WindowsHiddenUpdate -Hide $True