PowerShell for Windows Admins


November 2, 2013  2:50 PM

Useful PowerShell resources

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Want to know more about using PowerShell in these contexts:

File system
Arrays and Hash tables
Date, Time & Culture
Objects & Types
WMI
Regular Expressions
Then head over to http://powershell.com/cs/media/28/default.aspx

and look at the PowerTips Monthly volumes

Enjoy

October 31, 2013  2:58 PM

A thought for Halloween

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Just a quick thought

31 OCT = 25 DEC

Enjoy


October 31, 2013  11:58 AM

Book offers from Manning

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

those really nice people at www.manning.com have some real bargains this weekend:

Thursday October 31–Half off all MEAPs

Friday November 1–Half off all pBooks

Saturday November 2–Half off all eBooks

Sunday November 3–Half off any purchase

enjoy


October 30, 2013  3:05 PM

Using WQL in PowerShell

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

WMI Query Language – WQL – is used to either form a query directly or indirectly in the –Filter parameter of Get-WmiObject and Get-CimInstance.

$query = “SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3″
Get-CimInstance -Query $query

OR using the –Filter parameter

Get-CimInstance -ClassName Win32_LogicalDisk -Filter “DriveType = 3″

WQL is a limited subset of SQL.

If you want to find out more there is a help file available in PowerShell 3.0 and above

get-help about_WQL -ShowWindow


October 30, 2013  2:35 AM

SCCM 2012 lunches deal of the day

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Manning’s deal of the day is Learn SCCM 2012 in a Month of Lunches – get 50% off – today only at www.manning.com


October 29, 2013  4:44 PM

where syntax

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

This type of construction has been part of PowerShell since the very beginning:

Get-Process | where {$_.Handles -gt 500}

Get some data and use where-object to filter the data based on the value of some property. $_ represents the object on the pipeline.

PowerShell 3.0 introduced a simpler syntax

Get-Process | where Handles -gt 500

which is shorthand for

Get-Process | where -Property Handles -gt -Value 500

At which point it becomes obvious what is happening – you are comparing a property against a value. There are a whole set of comparison operators you can use in this manner – see the help file for details.

This new syntax makes life much easier when you only have a single comparison to perform – you need to use the old style syntax if you need to test on two properties.

The problem is that I don’t see this syntax being used that much. If you are using PowerShell 3.0 or above I recommend changing to the new style syntax. It does save typing.


October 29, 2013  3:29 PM

A new lunches book

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Manning have started the early access program (MEAP) for Learn SCCM 2012 in a Month of Lunches – http://www.manning.com/bannan

SCCM is a major component for managing your environment. Looking forward to reading it – especially as it has a chapter devoted to PowerShell


October 28, 2013  3:09 PM

Powershell help file updates

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The updated PowerShell help files are available for all but a handful of modules – the outstanding ones should be available this week.

Time to run update-help


October 28, 2013  2:00 PM

Outputting collections from AD

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Have you ever tried anything like this:

Get-ADUser -Filter * -Properties * |
Select Name, LastLogondate, PasswordNeverExpires, Enabled,
@{N=’OU’; E={($($_.distinguishedName) -split “,”,2)[1] }},
Memberof |
Export-csv -Path users.csv -NoTypeInformation

You want some basic information about the users plus their group membership

What you get is this

Name : Fred Friday
LastLogondate :
PasswordNeverExpires : False
Enabled : True
OU : OU=Mailboxes,DC=Manticore,DC=org
Memberof : Microsoft.ActiveDirectory.Management.ADPropertyValueCollection

The data is OK apart from the group membership where you get the name of the object.

All you need is a little trick with sub expressions

Get-ADUser -Filter * -Properties * |
Select Name, LastLogondate, PasswordNeverExpires, Enabled,
@{N=’OU’; E={($($_.distinguishedName) -split “,”,2)[1] }},
@{N=’Groups’; E={$($_.Memberof)}} |
Export-csv -Path users.csv –NoTypeInformation

and then the data comes through

Name : Fred Friday
LastLogondate :
PasswordNeverExpires : False
Enabled : True
OU : OU=Mailboxes,DC=Manticore,DC=org
Groups : CN=Wednesdaylist,OU=DistributionGroups,DC=Manticore,DC=org

Enjoy


October 28, 2013  1:36 PM

Setting AD attributes from a CSV file

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Back in this post http://richardspowershellblog.wordpress.com/2012/02/29/setting-a-users-home-directory/ I looked at setting the users home directory. I recently got a question about using a CSV file for input.

CSV files have been around for years and are likely to be with us for a long time to come – its a very useful and compact format. using a CSV file to set attributes is a two stage process – read the data then make the changes.

I’ll use the home directory data as an example. If you have a csv file with an entry for every user looking like this:

samaccountname : sjones
Drive : H:
Home : \\server2\Home\sjones

You can then do this:

Import-Csv .\homes.csv |
foreach {
Set-ADUser -Identity $_.samaccountname -HomeDirectory $_.Home -HomeDrive $_.Drive -PassThru
}

If the attribute doesn’t have a parameter then:

Import-Csv .\homes.csv |
foreach {
Set-ADUser -Identity $_.samaccountname -Replace @{HomeDirectory = “$($_.Home)”; HomeDrive = “$($_.Drive)”} -PassThru
}


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: