pátek 7. srpna 2009

Šikové CMDLETy

Velikosti mailboxů

Get-MailboxStatistics | Sort-Object TotalItemSize –Descending | ft DisplayName,@{ expression={$_.TotalItemSize.Value.ToMB()}},ItemCount

Seznam počítačů v AD + zobrazení stavu (online/offline)

$strCategory = "computer"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher$objSearcher.SearchRoot = $objDomain$objSearcher.Filter = ("(objectCategory=$strCategory)")
$colProplist = "name"foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults){ $objComputer = $objResult.Properties [string]$CN = $objComputer.name
$QueryString = ('Select StatusCode From Win32_PingStatus Where Address = "' + $CN + '"') $ResultsSet = Gwmi -Q "$QueryString" If ($ResultsSet.StatusCode -Eq 0)  {write-host -foreground green "$CN : Online"} else  {write-host -foreground red "$CN : Offline"}}

Exportování seznamu uživatelů s mailboxem

Get-Mailbox | Get-User | select-object identity,department | Export-Csv -Encoding utf8 -noTypeInformation users.csv

Aktivace výjimky SMB ve firewallu

get-netfirewallrule -displaygroup ‘File and Printer Sharing’ | enable-netfirewallrule 

Stav baterie

Get-WmiObject -Class Win32_Battery

Enabled Computers
Get-ADComputer -Filter 'Enabled -eq $true' -Properties * | Sort LastLogonDate | FT Name, OperatingSystem, LastLogonDate -Autosize
(&(&(&(objectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=2))))

Disabled Computers
Get-ADComputer -Filter 'Enabled -eq $false' -Properties * | Sort LastLogonDate | FT Name, OperatingSystem, LastLogonDate -Autosize
(&(&(&(&(objectCategory=computer)(objectClass=user)(useraccountcontrol:1.2.840.113556.1.4.803:=2)))))

Enabled Users
Get-ADUser -Filter 'Enabled -eq $true' -Properties * | Sort LastLogon | FT Name, LastLogon -Autosize
(&(objectCategory=User)(!userAccountControl:1.2.840.113556.1.4.803:=2))

Disabled Users
(&(objectCategory=User)(userAccountControl:1.2.840.113556.1.4.803:=2))

Computer Inventory

http://www.powershellpro.com/why-i-no-longer-hate-writing-documentation/614/

Žádné komentáře: