Stories from the PowerShell Trenches: Day 1

Adam Bertram

Adam Bertram

Read more posts by this author.

If you’d like to share your story I’ll be happy to share it here on my blog or at powershell.org. Just let me know in the comments. I’m always interested in how others are using PowerShell.

Without further ado, here’s our first story brought to you by Paul Abke.

We use several software packages that use Excel extensively.

The packages all use Excel add-ins to offer special functionality. After time, the Excel15.xlb file gets bloated and causes Excel to behave badly.

I wanted an automated way to delete the bloated files in all the users’ profiles. Fortunately, we use Citrix XenApp so all our users’ profiles are centrally located.

I used get-item | get-member to discover the delete method for the get-item cmdlet. Using get-help | get-item will uncover that the get-item cmdlet supports wildcards in the path parameter so searching for the Excel15.xlb file was easy.

ForEach-Object loops through the results of get-item. $_ represents the current item in the pipeline so using the delete method took just a few keystrokes.

Test before using it in a production environment!

Get-Item G:\Profiles$\TSProfiles\*\*\AppData\Roaming\Microsoft\Excel\*.xlb | ForEach-Object {
    $_.delete()
}

Subscribe to Adam the Automator

Get the latest posts delivered right to your inbox

Looks like you're offline!