#requires -version 2.0 <# DSAMAIN/NTDSUTIL GUI dedicated for the management of Active Directory snapshot. Version: 1.0 Author: Augagneur Alexandre Created on: 15/08/2011 #> #Check if the script is running on a DC 2008/2008R2 function CheckPrerequisites() { $OSCaption = (Get-WmiObject -Class win32_OperatingSystem -namespace "root\CIMV2").Caption if ( $OSCaption -like "*2008*" ) { $Feature = Get-WmiObject -Class win32_ServerFeature -namespace "root\CIMV2" | where-object { $_.Name -match "Active Directory Domain Controller" } if ( (!$Feature) ) { $mbNoDc = [System.Windows.Forms.MessageBox] $btnNoDc = [Windows.Forms.MessageBoxButtons]::OK $NoDcMsg = [windows.forms.MessageBoxIcon]::Error $mbNoDcShow = $mbNoDc::show("The application can only be used on an Active Directory Domain Controller.", ` "ADSM",$btnNoDc,$NoDcMsg) return $false } }else { $mbNo2008 = [System.Windows.Forms.MessageBox] $btnNo2008 = [Windows.Forms.MessageBoxButtons]::OK $No2008Msg = [windows.forms.MessageBoxIcon]::Error $mbNo2008Show = $mbNo2008::show("The operating system does not support Active Directory Snapshots.", ` "ADSM",$btnNo2008,$No2008Msg) return $false } return $true } # Locate the NTDS Database File through Registry function GetNTDSParameters() { if ( Test-Path -Path "HKLM:\SYSTEM\CurrentControlSet\services\NTDS\Parameters" ) { $RegKeysNtdsParameters = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\services\NTDS\Parameters" $RegKeyDsaDbFile = $RegKeysNtdsParameters.'DSA Database File' $RegExDsaFile = "(?\w{1,}.?):\\(?.{1,})" if ( $RegKeyDsaDbFile -match $RegExDsaFile ) { $GLOBAL:NTDSFileLetter = $matches.Letter $GLOBAL:NTDSFilePath = $matches.Path } } } #Check if a snapshot is mounted function CheckIfSnapshotMounted($GUID,$List) { foreach ( $Item in $List ) { if ($GUID -match $Item.Guid) { return $true } } return $false } #Display in the Datagridview if each snapshot is mounted #Add items to the combobox "mount point" function GetListMountedSnapshots() { GetNTDSParameters $cbMountedPoints.items.clear() $GLOBAL:GBListMounted = @() $RegexMountedSnapshots = "(?\d{1,}.?):\s{1}(?\d{4}/\d{2}/\d{2}):" $RegexMountedSnapshots += "(?