Link to home
Start Free TrialLog in
Avatar of John Darby
John DarbyFlag for United States of America

asked on

Powershell script assist

I have a script which has annotations and I am not sure how to work the syntax. The code I pasted below is as far as I have gotten today. I would greatly appreciate your insight to the syntax and logic of this script!!!

The gist of the script I am looking to execute is this...

1. purge the local kerberos ticket cache
2. determine the name of the local domain
3. get a kerberos TGT
4. get the local AD site name
5. get a kerberos TGT
6. get a list of domain controllers in local site
7. request a kerberos ticket from each domain controller (kerblist get ldap/dcnamehere)
8. if request is successful for each domain controller return to run script again
9. if a request against a domain controller returns an ERROR output domain controllername and timestamp to file
10. continue down list of domain controllers and once complete, start again
11. set the file write for ERROR to append
#Purge local Kerb list
kerblist purge all

# Get Domain information  
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()   

#Get a Kerberos TicketGettingTicket (TGT)
kerbist get krbtgt/$domain.name

#Get AD Site Name
function Get-ADComputerSite(%COMPUTERNAME%)
{
$site = nltest /server:$ComputerName /dsgetsite
if($LASTEXITCODE -eq 0){ $site[0] }
}


#Grab all DC hostnames in site ($dcs)
$dcObj = [adsi]"LDAP://OU=domain controllers,dc=domain,dc=local"
$dcs = $dcObj.PSBase.Children | % { $_.name }
$dcs > .\localsitedclist.txt

#LDAP query against all DCs in site
function Get-Kerblist 
{
$kerblist = kerblist get ldap/$dcs
}


for /F %%s in (localsitedclist.txt) do Get-Kerblist

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John Darby

ASKER

Thanks Chris! The get-dns cmdlet is most excellent. The 3 options above are more than worth the price of admission!  

Thanks, Brother Chris!

JD