Created
May 27, 2023 05:37
-
-
Save Mehran/69ed3182865c79a4a81380e567733b52 to your computer and use it in GitHub Desktop.
Powershell
This file contains hidden or 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-ADUser -Filter {(Enabled -eq "True") -and (PasswordNeverExpires -eq "True")} -Properties SamAccountName, PasswordNeverExpires | ft Name, SamAccountName, PasswordNeverExpires | |
Get-ADUser -Filter {(Enabled -eq "True") -and (PasswordNeverExpires -eq "False")} -Properties SamAccountName, PasswordLastSet | Where PasswordLastSet -le (Get-Date).AddDays(-30) | ft Name, SamAccountName, PasswordLastSet | |
Get-ADUser -Filter {(Enabled -eq "True") -and (PasswordNeverExpires -eq "False")} -Properties SamAccountName, LastLogon | Where-Object {([datetime]::FromFileTime($_.LastLogon) -le (Get-Date).AddDays(-90))} |ft Name, SamAccountName, {[datetime]::FromFileTime($_.LastLogon)} | |
Get-ADGroupMember 'domain admins' | select name,samaccountname | |
Get-ADGroupMember 'enterprise admins' | select name,samaccountname | |
Get-LocalGroupMember "admins local fhbf" | |
$ipRange = "192.168.1.1-192.168.1.10" # Specify the desired IP range | |
$domain = "domain" | |
$ipAddresses = Get-WmiObject -Class Win32_PingStatus -Filter "Address LIKE '$ipRange'" | | |
Where-Object { $_.StatusCode -eq 0 } | | |
Select-Object -ExpandProperty Address | |
foreach ($ipAddress in $ipAddresses) { | |
$computer = [System.Net.Dns]::GetHostByAddress($ipAddress).HostName | |
$admins = Get-WmiObject -Class Win32_GroupUser ` | |
-ComputerName $computer ` | |
-Filter "GroupComponent=""Win32_Group.Domain='$domain',Name='Administrators'""" | | |
ForEach-Object { $_.PartComponent -match "Name=`"(.+?)`"" | Out-Null; $Matches[1] } | |
Write-Host "Local administrators on $computer ($ipAddress):" | |
$admins | |
Write-Host "----------------------" | |
} | |
sc create ServiceName binPath= "C:\Path\to\executable.exe" displayname= "My Service" description= "Description of my service" | |
New-Service -Name "ServiceName" -BinaryPathName "C:\Path\to\executable.exe" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment