PowerShell for Windows Admins


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
}

October 27, 2013  11:09 AM

WMF 4.0 now available

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

You’ve probably seen this already but just in case – Windows Management Framework 4.0 is now available to download. It includes PowerShell 4.0 and Desired State Configuration plus updates to PowerShell Web Access. WinRm is also part of the package.

Versions are available for:

Windows 2012

Windows 7 SP1

Windows 2008 R2 SP1

Windows 7 Embedded

There isn’t a version for Windows 8 – it comes as part of the Windows 8.1 upgrade

Windows 8.8 and Server 2012 R2 come with WMF 4.0 pre-installed.

You need .NET 4.5 installed before installing WMF 4.0


October 27, 2013  10:48 AM

More Scripting Guy posts

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I’ve had some more articles posted on the Scripting Guy blog

http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/27/the-admin-s-first-steps-local-group-membership.aspx

http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/20/powertip-find-members-of-critical-groups-with-powershell.aspx

http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/20/the-admin-s-first-steps-empty-groups.aspx

Enjoy


October 14, 2013  2:22 AM

Sunday’s Scripting Guy blog

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I had another post in my Admin’s First Steps series on the Scripting Guy blog yesterday –

http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/13/powertip-use-poweshell-to-start-service-on-remote-machine.aspx

http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/13/the-admin-s-first-steps-discovering-shares.aspx

Enjoy


October 11, 2013  11:48 AM

Summit 2014 Speaker list “leak”

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Possible speakers at the PowerShell Summit in April 2014.

http://powershell.org/wp/2013/10/10/leak-powershell-summit-na-2014-speakers/

If you want to see, hear and talk to these PowerShell experts – the PowerShell summit is unlike most other conferences as the speakers are available

Now is the time to register – http://powershell.org/wp/community-events/summit/powershell-summit-north-america/summit-registration/

Some places will be reserved for the New Year for late bookings but I don’t think there’ll be many. We sold out last year & had a brilliant 3 days. This is going to be better


October 10, 2013  1:33 PM

Testing Service Health

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Two new posts from me on the Scripting Guy blog

http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/10/powertip-change-output-object-property-names-with-powershell.aspx

http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/10/the-admin-s-first-steps-testing-service-health.aspx

Enjoy


October 9, 2013  2:05 PM

AD Management MEAP v 11

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The next MEAP for AD Management in a Month of Lunches is available from Manning – www.manning.com/siddaway3

This adds chapter 20 on maintaining and monitoring AD together with appendix A on searching AD

Enjoy


October 8, 2013  2:48 PM

ADs 1000 object limit

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

By default when you query AD using a script or cmdlet you won’t get more than 1000 objects returned. If your AD contains 4000 users and you run

Get-ADuser –filter *

You’ll still only get the first 1000 users returned.

This is by design to prevent you accidentally unleashing the “query from hell” and grinding your poor domain controller into the ground.

Of course if you only have 900 users you’ll never see a problem.

You can get a bigger result set using the ResultSetSize parameter.

Set it to a value bigger than you expect and you’ll be fine.

The documentation says that using a value of $null (which is supposedly default) will return all objects that match you filter. I need to test but I don’t think that’s right


October 7, 2013  1:10 PM

Desired State Configuration

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Desired State Configuration is the headline item in PowerShell 4.0

Steven Murawski has started a series of posts on PowerShell.org. The first two posts are available

http://powershell.org/wp/2013/10/02/building-a-desired-state-configuration-infrastructure/

http://powershell.org/wp/2013/10/03/building-a-desired-state-configuration-pull-server/

More to come


October 5, 2013  5:59 AM

Common mistakes–size constants

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I can’t count the number of times I’ve seen something like this:

Get-WmiObject -Class Win32_LogicalDisk -Filter {DriveType = 3} |
select @{N=’Capacity'; E={[math]::Round(($_.Size / 1073741824), 2)}}

What’s wrong this?

The use of 1073741824 – in case you don’t recognise the number its 1 gigabyte.

Wouldn’t you prefer to do this

Get-WmiObject -Class Win32_LogicalDisk -Filter {DriveType = 3} |
select @{N=’Capacity'; E={[math]::Round(($_.Size / 1gb), 2)}}

That’s right divide by 1 gigabyte.

PowerShell recognises the main sizes you’ll be using – from KB to PB (petabyte)

1kb, 1mb, 1gb, 1tb, 1pb |
foreach {
“{0,16}” -f $psitem
}

1024
1048576
1073741824
1099511627776
1125899906842624

Which would you prefer to type 1pb or 1125899906842624 ?

Using the size constants is less prone to error and also reminds you of what you are trying to achieve.


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: