PSScript giving error

I have generated a script which is supposed to disable running services for google update.
Here is the code:

############################# UPDATES ARE OFF #########################################################

            ## -- Rename the Google Update executable file
     $Chrome = "${env:ProgramFiles(x86)}\Google\Update\GoogleUpdate.exe";
     If(Test-Path($Chrome)){Rename-Item -Path $Chrome -NewName "CantUpdate_GoogleUpdate.exe.bak" -Force};

$Chrome = "$env:ProgramFiles\Google\Update\GoogleUpdate.exe";
    If(Test-Path($Chrome)){Rename-Item -Path $Chrome -NewName "CantUpdate_GoogleUpdate.exe.bak" -Force};

        ## -- Stop and disable the Google Update services that run to update Chrome
    $GUpdateServices = (Get-Service | ?{$_.DisplayName -match "Google Update Service"}).Name;
    $GUpdateServices | % {
   $status = (Get-Service -Name $_).Status;
    If($status -ne "Stopped"){Stop-Service $_ -Force};
        $sType  = (Get-Service -Name $_).StartType;
           If($sType -ne "Disabled"){Set-Service $_ -StartupType Disabled};
       };

    ## -- Disable Chrome Update Scheduled Tasks

$GUdateTasks = (Get-ScheduledTask -TaskPath “” -TaskName “GoogleUpdate”)
GUdateTasks | % {If(.State -ne “Disabled”){Disable-ScheduledTask -TaskName $.TaskName}}

But I am getting below error message. please suggest:

image

I think you need to use either -TaskPath OR -TaskName but not both at the same time.

I used:
Set-Service -Name gupdate -Status Stopped
Set-Service -Name gupdate -StartupType Disabled
Set-Service -Name gupdatem -Status Stopped
Set-Service -Name gupdatem -StartupType Disabled

1 Like

Hi All,

Thanks for the help, I was able to solve the issue which was occurring in the script.
I am not sure why the taskname and taskpath cannot be used in one line as it worked fine if used in a separate ps file.