Hi Everyone,
I’m really new to PowerShell. My company is changing the paths for our Intranet site on some departments. Because of that I need to change some of the paths in the registry starting with OneNotebooks. I managed to write a script but it changes all the intranet sites. I only need to change it for certain departments like the ones below and I couldn’t figure it out. Thank you eveyone in advance for their help.
http://oldpath.test.intra/nemv
http://oldpath.test.intra/finance
http://oldpath.test.intra/sites/procurement/
http://oldpath.test.intra/Comm
http://oldpath.test.intra/Departments/SKS/
http://oldpath.test.intra/ro/
http://oldpath.test.intra/nitd
http://oldpath.test.intra/cniedr
http://oldpath.test.intra/communities/sig
########################
#Set Variables
$UserName = [Environment]::UserName
$OneNoteBooks = “C:\backup\onenotenotebooks.txt”
$NewPath = ‘//Newpath.test.net/’
$Folder = “C:\backup”
Create a new folder if not exist file
IF(-Not(Test-Path $Folder)){
“Creating Backup Folde…!”
New-Item -Path $Folder -ItemType Directory | Out-Default
}
“Done…!”
Start Logging
Start-Transcript -Path “C:\backup\onenote.log”
#Copy the OneNote backup folder
“Copying OneNote Backup Folder” | Out-Default
Copy-Item "C:\Users$UserName\Local Settings\14.0\Backup" “C:\backup” -Recurse -Force | Out-Default
“Done…!”
Check if there is an existing file
IF(-Not(Test-Path $OneNoteBooks))
{
“Creating New Text File to Export Registry Keys For backup” | Out-Default
New-Item -Path $OneNoteBooks -ItemType File | Out-Default
}
#If exists change the file name with the date for backup purposes
ELSE{
“Found Existing Text File. Changing The Name With The Current Date…!”
$Date = Get-Date -Format dd.MM.y.H.mm.s
Move-Item -Path “C:\backup\onenotenotebooks.txt” $Folder$Date.txt -Force | Out-Default
New-Item $OneNoteBooks -ItemType File | Out-Default
}
Exporting OneNote SharePoint Notebooks and Correcting them to the new URL
“Exporting OneNote SharePoint Notebooks and Correcting them to the new URL…!” | Out-Default
Push-Location
Set-Location ‘HKCU:\Software\Microsoft\Office\14.0\Onenote\opennotebooks’
$OneNoteReg = Get-Item .
$OneNoteReg.Property | ForEach-Object {
$CurrentValue = $OneNoteReg.GetValue($)
$NewValue = $CurrentValue.ToString() | ForEach-Object { $ -replace ‘//oldpath.test.intra/’, $NewPath }
Set-ItemProperty ‘HKCU:\Software\Microsoft\Office\14.0\Onenote\opennotebooks’ -Name $_ -Value $NewValue
[PSCustomObject][Ordered]@{
“Value Name”=$_
“Original Value”=$CurrentValue
“Updated Value”=$NewValue
}
} | Format-Table -AutoSize | Out-File $OneNoteBooks -Width 500
Pop-Location
“Done…!” | Out-Default
“Migration finished. Please check the log file for any errors…!” | Out-Default
#Stop Logging
Stop-Transcript