This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# powershell find duplicate files md5 | |
# powershell get childitem filter duplicates | |
# script to find duplicate files windows | |
# powershell duplicate files md5 | |
gci * -Recurse | get-filehash -Algorithm MD5 | Group-Object hash | ?{$_.count -gt 1} | select @{n='DupeCount';e={$_.Count}}, @{n='DupeFiles';e={$_.Group.Path -join [System.Environment]::NewLine}} | Out-GridView | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get dnsroot | |
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name | |
#get domain distinguishedname | |
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().GetDirectoryEntry().Properties["distinguishedName"] | |
#list domain controllers | |
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().FindAllDomainControllers().Name | |
#get PDC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$TargetDC = “dc1.contoso.com” | |
Test-NetConnection -ComputerName $TargetDC -Port 88 # Kerberos | |
Test-NetConnection -ComputerName $TargetDC -Port 135 # RPC | |
Test-NetConnection -ComputerName $TargetDC -Port 139 # NetBIOS SS | |
Test-NetConnection -ComputerName $TargetDC -Port 389 # LDAP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# validate srv records | |
$domain = 'contoso.com' | |
$sites = 'Dallas','Austin','Houston' | |
foreach($site in $sites){ | |
@" | |
_kerberos._udp.$domain | |
_kpasswd._udp.$domain | |
_gc._tcp.$domain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module ActiveDirectory | |
$samID = "USERIDHERE" | |
$Host.UI.RawUI.WindowTitle = "Finding lockouts for $samID" #change window title just incase we have multiple running | |
$DCs = Get-ADDomainController -Filter * | select -ExpandProperty name | |
# do infinite loop, sleeping for 60 seconds each iteration, and when i find the account locked search for lockout source and log it | |
do{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PS C:\Windows\system32> $htVmDatacenters.Values | %{ | |
Get-WmiObject -ComputerName $_.Replace("`$", '') -Query "SELECT * FROM Win32_GroupUser" | ?{([WMI]$_.GroupComponent).Caption -like "*\Administrators"} | %{ | |
$PartComponent = $_.PartComponent -replace "^.*\\cimv2:","Class=" -replace '"','' -replace "[\.,]",[environment]::NewLine | ConvertFrom-StringData | |
[PSCustomObject]@{ | |
LocalGroup = ([WMI]$_.GroupComponent).Caption | |
Member = "$($PartComponent.Domain)\$($PartComponent.Name)" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# directoryentry (connect to specific dc:port) | |
$de = ([ADSI]"LDAP://$($ADDomainController.HostName):$($ADDomainController.LdapPort)") | |
# directorysearcher | |
$ds = New-Object System.DirectoryServices.DirectorySearcher($de,"(objectclass=user)") | |
$ds.PageSize=1000 | |
# invoke | |
$ds.FindAll() | %{"do stuff with $_"} | |
$thisuser = $ds.FindOne() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$AuthenticationType = [System.DirectoryServices.AuthenticationTypes]::Secure | |
$DirectoryConnection = New-Object -TypeName System.DirectoryServices.Protocols.LdapConnection -ArgumentList "ldapserver.domain.com:777,uid=newuser,ou=people,dc=company,dc=com", $password , $AuthenticationType | |
$DirectoryConnection.Bind() | |
$DirectoryRequest = New-Object -TypeName System.DirectoryServices.Protocols.AddRequest | |
$DirectoryRequest.DistinguishedName = "uid= xxxx, ou=user, o=company" | |
$DirectoryRequest.Attributes.Add((New-Object -TypeName System.DirectoryServices.Protocols.DirectoryAttribute -ArgumentList "objectclass",@("top","organizationalPerson","person","inetorgperson","inetuser","mailrecipient","pwmuser","posixAccount"))) | Out-Null | |
$DirectoryRequest.Attributes.Add((New-Object -TypeName System.DirectoryServices.Protocols.DirectoryAttribute -ArgumentList "cn",($FirstName+" "+$LastName))) | Out-Null | |
$DirectoryConnection.SendRequest($DirectoryRequest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define your query filter | |
$LDAPfilter = "(samaccountname=*)" | |
# define the object attributes you want returned | |
$Attributes = @" | |
samaccountname | |
givenname | |
surname | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# finds kms servers from DNS and checks if the port is open | |
Resolve-DnsName "_vlmcs._tcp.$([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Name)" -Type all | %{Test-NetConnection -ComputerName $_.NameTarget -Port 1688} |
NewerOlder