Garacesh Posted November 26, 2020 Posted November 26, 2020 Bit of another bump, y'know when you realise you didn't quite get it right? The script posted above copies the most recent version to CurrentVersion only if current version does not exist If CurrentVersion already exists, you end up with CurrentVersion\VersionNumber The following script fixes that [color="#008000"]# Google Drive File Stream creates a new directory each time it updates. # This results in the shortcut in the redirected start menu becoming invalid or pointing to older versions. # This script copies the latest version to the same folder to keep the newest version at the same destination with each update.[/color] [color="#000080"]If[/color] ([color="#0000FF"]Test-Path[/color] [color="#000080"]-Path[/color] [color="#800000"]"C:\Program Files\Google\Drive File Stream"[/color]) { [color="#008000"]# Get latest version folder path.[/color] [color="#000080"]ForEach[/color] ([color="#FF8C00"]$Property[/color] [color="#000080"]in[/color] ([color="#0000FF"]Get-ChildItem[/color] [color="#800000"]"C:\Program Files\Google\Drive File Stream"[/color] [color="#000080"]-Directory[/color] | [color="#0000FF"]Where[/color] {[color="#FF8C00"]$_[/color].Name [color="#A9A9A9"]-inotmatch[/color] [color="#800000"]"Drivers|CurrentVersion"[/color]} | [color="#0000FF"]Select-Object[/color] [color="#000080"]-Last[/color] [color="#EE82EE"]1[/color])) { [color="#FF8C00"]$LatestVer[/color] = [color="#FF8C00"]$Property[/color].Name [color="#FF8C00"]$LatestVerFullPath[/color] = [color="#FF8C00"]$Property[/color].FullName } [color="#008000"]# Create CurrentVersion folder if it doesn't already exist, copy the latest version into it, overwrite any existing files.[/color] [color="#000080"]If[/color] ([color="#A9A9A9"]) { [color="#0000FF"]New-Item[/color] [color="#000080"]-ItemType[/color] [color="#EE82EE"]Directory[/color] [color="#000080"]-Path[/color] [color="#800000"]"C:\Program Files\Google\Drive File Stream\CurrentVersion"[/color] [color="#000080"]-Force[/color] } [color="#0000FF"]Copy-Item[/color] [color="#000080"]-Path[/color] [color="#FF8C00"]$LatestVerFullPath[/color][color="#EE82EE"]\*[/color] [color="#000080"]-Destination[/color] [color="#800000"]"C:\Program Files\Google\Drive File Stream\CurrentVersion\"[/color] [color="#000080"]-Recurse -Force[/color] [color="#008000"]# Delete all but the latest version.[/color] [color="#0000FF"]Get-ChildItem[/color] [color="#000080"]-Path[/color] [color="#800000"]"C:\Program Files\Google\Drive File Stream"[/color] [color="#000080"]-Directory[/color] | [color="#0000FF"]Where[/color] {[color="#FF8C00"]$_[/color].Name [color="#A9A9A9"]-inotmatch[/color] [color="#800000"]"Drivers|CurrentVersion|[/color][color="#FF8C00"]$LatestVer[/color][color="#800000"]"[/color]} | [color="#0000FF"]Remove-Item[/color] [color="#000080"]-Recurse -Force[/color] } 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now