Skip to content

Instantly share code, notes, and snippets.

@zbalkan
Last active June 5, 2023 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbalkan/7720039db8795bb5d89b6f57c0bfbebe to your computer and use it in GitHub Desktop.
Save zbalkan/7720039db8795bb5d89b6f57c0bfbebe to your computer and use it in GitHub Desktop.
$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