- Add function information
- Build the process
- Full script
- See it in action
Add function information
Powershell functions are blocks of code inside of a script for easy re-use, we can use them like we use cmdlets, we can set it’s own parameters and much more, we can even add information in it by using a comment block () .
All these informations can be accessed by using the Get-Help cmdlet:
Build the process
Building a process it’s more about debuggin it than just running it (the uninstallation in this case), we can’t know if a target is offline, or maybe the target doesn’t even have the software to be uninstalled, or maybe a key can be different from the collected key, like version key!
So, we need to imagine those errors possibilities and turn them into expected exits, and of course we also want to know if the software has been uninstalled and throw a success exit for that.
Follow the comments in the script below:
Finally it’s time to put it all together!
See it in action
In the animation below, I have tried first a software name that returns more than one object, that’s why the script stops since we want to remove only one specific software, then I change to another software name which returns only one object, then the script proceed asking for a computer list file, I select mine, which has only one name ‘ITFSCCM01’ (My lab has only two VM’s), The script first test the connection with ITFSCCM01, then search for a match of the classkey we have captured before, then if all those steps returns TRUE, the software is finally uninstalled, if I had more names in my computer list the script would proceed into these steps until the last one.
And this ends my very first article here! I’m really enjoying and trying to bring my best to the community.
I invite you to follow me on twitter, github, linkedin and facebook, please if you liked this article share it with your colleagues!
If you have any doubt or something went wrong, don’t hesitate to ask me help! 🙂