Curly Blue and the meaning of scripting – Part 4
Summary: Curly Blue learns how to use GitHub resources on PowerShell to clean out old office installations.
When we last saw our hero, Curly Blue, he had been hanging around the office of Azura and discovering the simple ways he could use Windows PowerShell with minimal learning.
In the past few days, he’s seen how easy it is to work and access files by date and time, use features that are built into the Active Directory Administrative Center (ADAC) to identify samples of PowerShell, and pull data by using the Common Information Model (CIM) cmdlets.
He was blinking in disbelief. Although he was a master of using the GUI and keyboard shortcuts and could minimize work in this fashion, the consistency and ease of use of PowerShell was untouchable!
He bade Azura goodbye and continued his tour down the hall with Linux when he encountered two of the deployment specialists, Loopy and Codestock.
Loopy began to dance about frantically with Codestock close at his heels. “Deployment! We need to deploy it now! Aihihighghighighi!!!”
Linux looked over at the pair. “What’s the panic about?”
Loopy indicated that as part of the project to migrate the content to the cloud, Office 365 was in scope. But, as part of the project, they had a double challenge.
“We need to get the entire network up to Office 2016, but, between our newest acquired division and us, there’s a bad mix of previous Office versions.” Loopy began to fret and shook with worry.
Curly Blue immediate understood the challenge. Every version of Microsoft Office had a similar process for the uninstall, but you needed to target the specific version in the uninstall string. You also needed to know if the previous version was a Click-To-Run edition, which had its own unique process.
Codestock piped up in a squeaky voice “We’ve found a solution, but it’s manual! If we go to this site on TechNet, there’s a tool that cleans things up beautifully. The challenge is we can’t easily automate it on 5,000 systems!”
Curly looked at the site in question and confirmed the process was manual. At Linux’s suggestion, he did a search for additional tools that involve PowerShell.
“You’ll probably find a pile of solutions on Github.com and the Powershell Gallery,” he suggested.
He entered the following search on Bing and found a potential tool that might solve his needs.
He was glad Linux had suggested that solution. There appeared to be a prebuilt solution that used both PowerShell and VBScript to do exactly that. With a little more research, Curly managed to vet that the solution was actually part of the Dev.Office.Com Github repository from Microsoft. This boosted his confidence in the solution.
He looked over at Loopy and Codestock, and both were still frantically waving their arms and screaming “Panic! Panic, we must! Panic! Aihighhghih!”
With his new confidence in Windows PowerShell, Curly acquired two test machines, each with unique versions of Microsoft Office. He downloaded the structure from Github to a common share and ran the following lines in PowerShell with administrative rights.
Remove-PreviousOfficeInstalls -RemoveClickToRunVersions $True -Remove2016Installs $True -KeepUserSettings $True -NoReboot $True
With no intervention on either machine, each system slowly but surely removed its copy of Microsoft Office.
“But, but!” shrieked Codestock, “our installer doesn’t run in PowerShell!! How do we run this?”
Curly looked over at Linux for a suggestion. “Curly, here’s the part I guess I never mentioned. A PowerShell script or .PS1 file is actually being launched by PowerShell.exe. If you run this in a command prompt with a
/?, you can see parameters to pass to it.”
Curly typed it in the Window as Linux suggested and got the following output.
Looking a little further, he found that he could use the following command to start the PowerShell script called RemoveIt.PS1 within a standard CMD script.
Start /wait powershell.exe -executionpolicy Bypass -file .\removeit.ps1
He passed the solution to Loopy and Codestock who looked at each other and blinked, “We won’t have to work late tonight! Woohoo!!!!”
Linux looked over at Curly. “Now you’re learning. Not only is PowerShell easy to use, but there are plenty of predefined solutions in the community for you to consume to make your job easier.”
Curly smiled. What a productive morning his first day on the job had been. With only a little bit of PowerShell knowledge, he couldn’t wait to see where this would take him!
Stay tuned for the final episode tomorrow on the Scripting Guys Holiday Special!
I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to them at firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. See you tomorrow.
Until then, always remember that with Great PowerShell comes Great Responsibility.
Sean Kearney Honorary Scripting Guy Cloud and Datacenter Management MVP