Kaseya Community

Powershell commands from Agent proceedures

  • I am attempting to run a couple of Powershell commands that appear to work when run from an elevated Powershell locally on a machine.

    Get-AppxPackage -AllUsers | where-object {$_.name –notlike “*store*” -And $_.name –notlike “*calc*”} | Remove-AppxPackage
    Get-appxprovisionedpackage –online | where-object {$_.name –notlike “*store*” -And $_.name –notlike “*calc*”} | Remove-AppxProvisionedPackage -online 

    I have attempted various things including running it as a .ps1 and individual commands. My agent proceedure currently looks like this:

  • Hi Mark - it seems to me like your commands should work. Note that it's getting more and more difficult to remove Microsoft's "oh so generous" inclusion of bloatware. We get about half of it via script and then end up removing the rest of it manually. Here's the script I run (it writes the results - mostly - to a file in the "C:\kworking" directly. If your working directory is in a different location you will need to make that change to the script in the very first line)

    $File = New-Item -type File "C:\kworking\app-remove.txt"

    $PackagesToRemove = @(






































    #Uninstall from current user and default user

    #This also prevents these packages from being installed on new users

    Start-Transcript -path $File

    ForEach ($package in $PackagesToRemove)


    Get-AppxPackage  | where-object {$_.packagename -like $package} | Remove-AppxPackage

    Get-AppxProvisionedPackage –Online | where-object {$_.packagename -like $package} | Remove-AppxProvisionedPackage -Online




  • Thanks for the script, I like it. Kinda new to the Kaseya scripting thing. Could you share hoe you implement the script? I have been able to manually run the commands successfully but I run into issues making them work in a agent procedure.

    Additional info
    [edited by: Mark McElvy at 2:28 PM (GMT -7) on May 25, 2016]
  • I copy the script to the agent's working directory and then impersonateUser and execute it as you are:

    As I mentioned, it successfully removes some of the garbage but there's still much we have to remove manually. This is very much a work in progress and I curse Microsoft for the direction they are taking and the additional work they are causing us.

  • I'm surprised you haven't mentioned the comparable holes in the firewall for all the bloatware! :)

    Nice work on the script.. I've just started tinkering with the firewall settings part and figured I'd get to the (cr)app removal later. I'll see what I can wrap up and post to complement this.


  • Thanks, gbarnas. Be more than happy to have any help getting this junk removed that you, or anyone else here, can provide. I've also been wondering about stopping some of it via our firewalls but haven't gotten that far, yet. The latest MS idiocy seems to be changing the file associations for PDF files so that they open in MS Edge instead of Adobe. Fortunately, there's a registry fix, for the moment, that stops that nonsense...