Posted in
Windows Powershell,
Windows Server |
No Comment | 1,913 views | 16/08/2009 20:11
I wrote this to get some information from Active Directory. I think it is pretty good for Active Directory management.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| function Get-ADInfo
{
$ADDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$ADDomainName = $ADDomain.Name
$Netbios = $ADDomain.Name.Split(".")[0].ToUpper()
$ADServer = ($ADDomain.InfrastructureRoleOwner.Name.Split(".")[0])
$FQDN = "DC=" + $ADDomain.Name -replace("\.",",DC=")
$Results = New-Object Psobject
$Results | Add-Member Noteproperty Domain $ADDomainName
$Results | Add-Member Noteproperty FQDN $FQDN
$Results | Add-Member Noteproperty Server $ADServer
$Results | Add-Member Noteproperty Netbios $Netbios
Write-Output $Results
} |
function Get-ADInfo
{
$ADDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$ADDomainName = $ADDomain.Name
$Netbios = $ADDomain.Name.Split(".")[0].ToUpper()
$ADServer = ($ADDomain.InfrastructureRoleOwner.Name.Split(".")[0])
$FQDN = "DC=" + $ADDomain.Name -replace("\.",",DC=")
$Results = New-Object Psobject
$Results | Add-Member Noteproperty Domain $ADDomainName
$Results | Add-Member Noteproperty FQDN $FQDN
$Results | Add-Member Noteproperty Server $ADServer
$Results | Add-Member Noteproperty Netbios $Netbios
Write-Output $Results
}
Usage sample:
$FQDN = (Get-ADInfo).FQDN
$Netbios = (Get-ADInfo).Netbios |
$FQDN = (Get-ADInfo).FQDN
$Netbios = (Get-ADInfo).Netbios
As you see, I used “Add-Member” to help you to get what you really need.