powershell

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-connection -tcpport 443 www.google.com

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