2

I should start this by saying, I enjoy solving problems with PowerShell, but my PowerShell skills are severely lacking. So if you do reply, please be as basic as you can about it :D

Microsoft Teams installs in AppData. Multiple users sign into various PCs, leave behind old versions of Teams which we now need to clean up without affecting currently signed in user and newer versions of Teams.

Because of this, I have been going down the route of VersionInfo.FileVerson to resolve this. The various methods I have tried, I can get so far with and then no further. I can list the FullName and FileVersion but I don't know how to omit the newer versions we want to leave alone.

I found this method which seems really clean compared to what I had written, and it gets me to the same stage as my script;

cd G:\test\users\ Get-ChildItem -Filter wire*.exe -Recurse |
    ForEach-Object {
        try {
            $_ | Add-Member NoteProperty FileVersion ($_.VersionInfo.FileVersion)
            $_ | Add-Member NoteProperty AssemblyVersion (
                [Reflection.AssemblyName]::GetAssemblyName($_.FullName).Version
            )
        } catch {}
        $_
        } | Select-Object FullName,FileVersion -outvariable info

From her, my idea is something along the lines of $info.where{$_.FileVersion -lt '3.4.4.0'}.

In testing this sort of thing with, for example, running services I can see how easy it is. So I am not sure how I do this, if someone could point me in the right direction for this I would be so grateful.

Lance U. Matthews
  • 15,725
  • 6
  • 48
  • 68
Fraser
  • 41
  • 2
  • 1
    If you cast the version number you get as string to a proper version type you can compare them correctly `[Version]'3.4.4.0'` – Olaf Mar 25 '21 at 00:29
  • An easy approach is just comparing the file version, and THEN, do something if found. `if($_.FileVersion -LT [Version]'3.4.4.0'){#do something}` – Abraham Zinala Mar 25 '21 at 01:44
  • Hi Olaf and Abraham, thanks for getting back to me. Perhaps where I was going wrong was not including [version]. I will try that tonight and report back :D – Fraser Mar 25 '21 at 10:55

1 Answers1

0

You could just delete the C:\users\<USERNAME>\Microsoft\teams folder for all users that aren't currently signed in.

Travis
  • 207
  • 1
  • 11
  • 1
    Yeah, I managed to write a script which can do this. If I run it myself, while I am signed in it seems to recognise the current user variable I am using and excludes it from my foreach. But we have hundreds of computers and when I try and run this through SCCM (which runs it as System) it doesn't work. I may revisit that approach as its a very simple solution if I can get it to ignore current user. May try getting it to check current user registry hive and see if that helps. – Fraser Mar 25 '21 at 10:55