commands for me to remember
Get-ADUser -filter * -SearchBase "OU=Users,OU=Domain,DC=Local" | format-table Name, UserPrincipalName
Get-ADOrganizationalUnit -Properties canonicalname -filter *| Sort-Object CanonicalName | Format-Table CanonicalName, DistinguishedName
Get-DHCPServerv4scope -ComputerName hofcon1 | Get-DHCPServerv4Lease -ComputerName server01
Get-ChildItem -Recurse -ErrorAction SilentlyContinue -Force -Path c:\ -Filter "mstd.exe"
Get-ADComputer -filter * | Format-Table Name, DistinguishedName
Get-ADComputer -Filter 'Name -like "computer*"' | Format-Table Name, DistinguishedName
Get-ChildItem x:\ -r|sort -descending -property length | select name, DirectoryName, @{Name="MB";Expression={[Math]::round($_.length / 1MB, 2)}} | Out-GridView
Get-ChildItem x:\ -r|sort -descending -property length | select name, DirectoryName, @{Name="MB";Expression={[Math]::round($_.length / 1MB, 2)}} | Out-File C:\Temp\x-files.txt -width 300
GetFileHash -Path c:\Windows\somefile.txt -Algorithm sha256
Get-ChildItem -Path "h:\000" -filter "*.xlsx" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-30))} | Remove-Item -force -verbose
test-netconnection -port 443 -computername www.google.com
# move fsmo-roles oneliner
Move-ADDirectoryServerOperationMasterRole -Identity “Target_DC_Name” –OperationMasterRole 0,1,2,3,4 -Confirm:$false -Force
Tässä on PowerShell-komento, joka listaa vain ESTABLISHED-tilassa olevat yhteydet ilman seuraavia Foreign Address -osoitteita:
localhost
127.0.0.1
10.31.100.16
netstat -ano | Select-String "ESTABLISHED" | Where-Object {
$_.Line -notmatch "\[\:\:" -and
$_.Line -notmatch "127\.0\.0\.1" -and
$_.Line -notmatch "localhost" -and
$_.Line -notmatch "10\.31\.100\.16"
}