PowerShell Registry Update File MRU and Place MRU

Recently, as part of a data migration project and in an effort to create a seamless user experience in Microsoft Office, the recent documents and recent places needed to be updated with a new server name.  This prevented any users from using this Office feature and having problems.

Using PowerShell to make updates to the File MRU and Place MRU accomplishes this goal.

# Create an empty array to contain collected data for parsing.
$MRUArray = @()
# Get-ChildItem recursively searches for File MRU and Place MRU. Get-Item returns
#  Name, Propery and PSPath that are used for updating the registry.  The items
#  are added to the variable.
$MRU = Get-ChildItem HKCU:\Software -recurse -ea SilentlyContinue `
| where { $_.Name -like "*File MRU" -or $_.Name -like "*Place MRU" } | Get-Item

# Foreach item returned above and contained in $MRU.
foreach ($Item in $MRU) {
	# Process the current item that matches "item*" and pipe to a new foreach loop.
	$Item.property -like "item*" |
	foreach {
		# Create a new object and add PSPaath, Item, and MRUPath to the array.
		$RegObject = New-Object system.Object
		$RegObject | Add-Member -type NoteProperty -Name "PSPath" -Value $Item.PSPath
		$RegObject | Add-Member -type NoteProperty -Name "Item" -Value $_
		$RegObject | Add-Member -type NoteProperty -Name "MRUPath" -Value (Get-ItemProperty $Item.PSPath).$_
		$MRUArray += $RegObject
	}
}

# Foreach object in $MRUArray.
foreach ($object in $MRUArray) {
	# Process the current object and replace server name.
	set-itemproperty -Path $object.PSPath -Name $object.Item `
	-value $object.MRUPath.replace("OldServer", "NewServer")
}