Monthly Archive

Categories

Active Directory Snapshots IV

The AD snapshots that we’ve taken aren’t any use until we’ve mounted them.

 

function mount-adsnapshot{
[CmdletBinding()]
param(
[Parameter(ParameterSetName="Index")]
[string]$index,
 
[Parameter(ParameterSetName="GUID")]
[string]$guid
)
PROCESS{
if ( -not ([Security.Principal.WindowsPrincipal]`
  [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
  [Security.Principal.WindowsBuiltInRole] "Administrator") ){
   Throw "Must run PowerShell as ADMINISTRATOR to perform these actions"
}
 
switch ($psCmdlet.ParameterSetName) {
   Index {ntdsutil snapshot "list all" "mount $index" quit quit}
   GUID {ntdsutil snapshot "mount $guid" quit quit}
}
 
}#process
}

 

We can mount the snapshot based on the GUID or the index. If we use the index in a script like this we need to perform a list all as part of the mount process so that we can find the correct index. This isn’t needed if we use ntdsutil directly at the command line.

 

When we’ve finished with the snapshot we can dismount it

function dismount-adsnapshot{
[CmdletBinding()]
param(
[Parameter(ParameterSetName="Index")]
[string]$index,
 
[Parameter(ParameterSetName="GUID")]
[string]$guid,
 
[Parameter(ParameterSetName="All")]
[switch]$all
 
)
PROCESS{
if ( -not ([Security.Principal.WindowsPrincipal]`
  [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
  [Security.Principal.WindowsBuiltInRole] "Administrator") ){
   Throw "Must run PowerShell as ADMINISTRATOR to perform these actions"
}
 
switch ($psCmdlet.ParameterSetName) {
   Index {ntdsutil snapshot "list all" "unmount $index" quit quit}
   GUID  {ntdsutil snapshot "unmount $guid" quit quit}
   All   {ntdsutil snapshot "unmount *" quit quit}
}
 
}#process
}

 

Again we need to list all snapshots if we want to use the index parameter.

Leave a Reply