Last active
June 5, 2023 09:45
-
-
Save zbalkan/7720039db8795bb5d89b6f57c0bfbebe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$officeFolder = Get-ChildItem -Path 'C:\Program Files\Microsoft Office\' -Filter Office* | Select-Object -ExpandProperty Name | |
$currentPath = 'C:\Program Files\Microsoft Office\'+$officeFolder+'\OneNote' | |
$newPath = 'C:\Program Files\Microsoft Office\'+$officeFolder+'\OneNoteOLD' | |
Rename-Item $currentPath $newPath | |
$drivers = pnputil /enum-drivers | |
$drivers -split '\r?\n' | select-string -Pattern "prnms006.inf" -Context 1,0 | % { | |
$pubName = $_.Context.PreContext[0] | |
} | |
$pubName | |
$regex = 'o\w*' | |
$oem = $pubName | select-string -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } | |
$oem = $oem+'.inf' | |
pnputil /delete-driver $oem /uninstall | |
pnputil /delete-driver $oem /force | |
$devices = pnputil /enum-devices | |
#take devices, split the lines with returns, match all lines with one note and include the line above | |
$devices -split '\r?\n' | select-string -Pattern "OneNote" -AllMatches -Context 1,0 | % { | |
#select 1 line above the match line | |
$instId = $_.Context.PreContext[0] | |
#clean up instance iD | |
$instId = $instId.substring($a.length - 52, 52) | |
#uninstall | |
pnputil /remove-device $instId | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment