The client I'm working with has Windows 2008 R2 with PowerShell 2.0 for their domain controllers. PowerShell is my preferred method for automating anything at this point but AD snapshots don't have any PowerShell cmdlets.
Fortunately Ashley McGlone, a Microsoft PFE, has created some PowerShell functions that help you manage and use AD snapshots. One of the coolest things in there is a function (Repair-ADAttribute) that lets you pull attributes from the snapshot and apply them to the same object in the production AD. You can read more about these functions and download them from these two locations:
- https://blogs.technet.microsoft.com/ashleymcglone/2014/04/24/oh-snap-active-directory-attribute-recovery-with-powershell/
- https://gallery.technet.microsoft.com/Active-Directory-Attribute-0f815689
$Choice = $snaps | Select-String -SimpleMatch '/' |
Select-Object -ExpandProperty Line |
Out-GridView -Title 'Select the snapshot to mount' -OutputMode Single
For my project, getting all of the DCs upgraded to using PowerShell v3 would take a while. I also didn't want to leave the project in a place where a whole bunch of manual steps were required to mount an AD snapshot older than the previous day. So, let's convert this to a method that works in PowerShell v2.
Now I needed a way to convert a list of snapshots in to a menu. My starting point was a TechNet discussion posting from Grant Ward (Bigteddy). You can view his solution for a discussion here:
Using that example I created the following code:
$choices = $snaps | Select-String -SimpleMatch '/' | Select-Object -ExpandProperty Line
$menu = @{}
$i=0
foreach ($s in $choices) {
$i++
Write-Host "$i --> $s"
$menu.Add($i,$s)
}
[int]$ans = Read-Host 'Enter selection'
$Choice = $menu.Item($ans)
This code takes the list of snapshots in the variable $snaps and does two things:
- Writes a menu to the screen
- Add each menu item to the array $menu
The snapshot functions mentioned here are no longer available at the links above. Ashley Mcgone has archived them on his own GitHub at https://github.com/GoateePFE/TechNetGalleryArchive. They are in a zip file.
ReplyDelete