Category Archives: PowerShell

PowerShell: special characters

powershell-logo

I bumped into this very interesting webpage which contains an overview of special characters used in PowerShell.

Here it is:

http://www.neolisk.com/techblog/powershell-specialcharactersandtokens

Advertisements

PowerShell: GetADComputer Cmdlet

powershell-logo

Step 1: Import AD module

Import-Module ActiveDirectory

This should work without problems on a domain controller.
If you’d like to do this on a non DC, you have to do some extra steps.

This is described here: http://blogs.msdn.com/b/rkramesh/archive/2012/01/17/how-to-add-active-directory-module-in-powershell-in-windows-7.aspx.  (I haven’t tested this …)

Step 2: Get-ADComputer

Now you can type the Get-ADComputer cmdlet with the filtering and output you need.

Examples

— Get a list of all properties for Get-ADComputer:

Get-ADComputer SYSTEMNAME -Properties *

— Filter on operating systems which contain “server”, select Name, Enable and OS – output: Format-Table, autowidth:

Get-ADComputer -Filter {(OperatingSystem -Like "*server*")} -Properties Name, OperatingSystem | Sort-Object Name | SELECT Name, Enabled, OperatingSystem | Format-Table -A

— Now only enabled servers and export to CSV:

Get-ADComputer -Filter {(OperatingSystem -Like "*server*") -And (Enabled -Eq "true")} -Properties  Name, OperatingSystem | Sort-Object Name | SELECT Name, Enabled, OperatingSystem | Export-CSV "Servers.csv" -NoTypeInformation -Encoding UTF8

Microsoft help page: https://technet.microsoft.com/en-us/library/ee617192.aspx