Powershell'in gücü system admin rolündeki kişiler için tartışılmaz. Zaman zaman üzerinde aging tanımı olmayan ortamlarda, düzgün yönetilemeyen domain ve dns ortamlarında aslında kapalı olan ve kapalı olmamasına rağmen domainden düşmüş computer objelerinin tespit edilebilmesi için aşağıdaki gibi bir script geliştirmiştim.
Umarım faydası olur, her türlü ek geliştirme için hakkiogretmen@gmail.com adresine mail atabilirsiniz.
Import-Module ActiveDirectory
$myServers = @("servers")
If (Test-Path "D:\Temp\PasswordLastSetResult.txt"){
Remove-Item "D:\Temp\PasswordLastSetResult.txt"
}
$Servers_OU = "OU=ServersOU,OU=ABCServersOU,DC=mydomain,DC=dmn,DC=com"
foreach ($myserver in $myServers)
{
$mycomp = Get-ADComputer –SearchBase $Servers_OU –SearchScope SubTree -Filter { OperatingSystem -like "Windows Server*"} -Properties PasswordLastSet,IPv4Address |
Select * | Where-Object {$_.Name -eq $myserver}
trap [System.Net.Sockets.SocketException] { continue; }
$ComputerName = $mycomp.Name
$ComputerPasswordLastSet = $mycomp.PasswordLastSet
$ComputerName + " " + $ComputerPasswordLastSet | out-File -Append "D:\Temp\PasswordLastSetResult.txt"
}
notepad.exe "D:\Temp\PasswordLastSetResult.txt"
Umarım faydası olur, her türlü ek geliştirme için hakkiogretmen@gmail.com adresine mail atabilirsiniz.
Import-Module ActiveDirectory
$myServers = @("servers")
If (Test-Path "D:\Temp\PasswordLastSetResult.txt"){
Remove-Item "D:\Temp\PasswordLastSetResult.txt"
}
$Servers_OU = "OU=ServersOU,OU=ABCServersOU,DC=mydomain,DC=dmn,DC=com"
foreach ($myserver in $myServers)
{
$mycomp = Get-ADComputer –SearchBase $Servers_OU –SearchScope SubTree -Filter { OperatingSystem -like "Windows Server*"} -Properties PasswordLastSet,IPv4Address |
Select * | Where-Object {$_.Name -eq $myserver}
trap [System.Net.Sockets.SocketException] { continue; }
$ComputerName = $mycomp.Name
$ComputerPasswordLastSet = $mycomp.PasswordLastSet
$ComputerName + " " + $ComputerPasswordLastSet | out-File -Append "D:\Temp\PasswordLastSetResult.txt"
}
notepad.exe "D:\Temp\PasswordLastSetResult.txt"
Yorumlar
Yorum Gönder