Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####################################################################################
- ### AD Functions Library, v.1.1
- ### Efimov (ge][) Gennady, http://gexeg.blogspot.com/
- ####################################################################################
- function GetForest($forestname){
- $ctx = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext(`
- [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::Forest, $forestname)
- $forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetForest($ctx)
- return $forest
- }
- function GetConfigNC($BindName){
- $rootDSE = [adsi]$("LDAP://$BindName/RootDSE")
- return $rootDSE.configurationNamingContext.Value.ToString()
- }
- function GetForestContext($forestName, $userName, $Password){
- if (-not $userName){
- return New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext(`
- [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::Forest, $forestname)
- }
- else {
- return New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext(`
- [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::Forest, $forestname, $userName, $Password)
- }
- }
- function GetScheduleInfo($schedule){
- $i_arr = @()
- if ($schedule.RawSchedule){
- $startT = New-Object System.TimeSpan(0,0,0,0)
- $current = $startT.Add("00:00:00")
- for ($d = 0; $d -lt 7;$d++){
- for($h = 0; $h -lt 24; $h++){
- for($m = 0; $m -lt 4; $m++){
- if (-not $schedule.RawSchedule[$d,$h,$m]){
- if ([System.TimeSpan]::Compare($startT, $current) -eq -1){
- $i_arr += [object]$(@($startT, $current.Subtract("00:00:01")))
- }
- $startT = $current.Add("00:15:00")
- }
- $current = $current.Add("00:15:00")
- }
- }
- }
- if ([System.TimeSpan]::Compare($startT, $current) -eq -1){
- $i_arr += [object]$(@($startT, $current.Subtract("00:00:01")))
- }
- }
- return $i_arr
- }
- function ScheduleToString($timespan_arr){
- [string[]]$str = @()
- for($i = 0; $i -lt $timespan_arr.Length/2; $i++){
- $str += @($timespan_arr[$i*2].ToString() + "-" + $timespan_arr[$i*2+1].ToString())
- }
- return "{" + [System.String]::Join(",", $str) + "}"
- }
- function GetSiteOptionInfo($siteOption){
- $opts = @(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024)
- [string[]]$str = @()
- foreach($op in $opts){
- if (($siteOption -band $op) -eq $op){
- $str += ([System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteOptions]$op).ToString()
- }
- }
- return [System.String]::Join(",", $str)
- }
- function GetUGMCSite($siteDE){
- $ntdsset = $siteDE.PSBase.Children.PSBase.Find("CN=NTDS Site Settings", "nTDSSiteSettings")
- if ($ntdsset -and $ntdsset.PSBase.Properties.Item("msDS-Preferred-GC-Site")){
- return [adsi]"LDAP://$($ntdsset.PSBase.Properties.Item(`"msDS-Preferred-GC-Site`").Value.ToString())"
- }
- else {
- return $null
- }
- }
- function GetSiteLinkOptions($sitelink){
- [string[]]$str = @()
- $str += "DataCompressionEnabled: {0}" -f $sitelink.DataCompressionEnabled.ToString()
- $str += "NotificationEnabled: {0}" -f $sitelink.NotificationEnabled.ToString()
- $str += "ReciprocalReplicationEnabled: {0}" -f $sitelink.ReciprocalReplicationEnabled.ToString()
- return [system.String]::Join(";", $str)
- }
- function GetTrustOptions($trust){
- return "-"
- }
Advertisement
Add Comment
Please, Sign In to add comment