O R G A N I C / F E R T I L I Z E R: 04.10

Apr 15, 2010

comparing home directories to user names with powershell

aside from just enjoying scripting, i particularly love scripting requests that start with something like -- “i want to know if this is possible…”.  my coworker put it best about why scripting is enjoyable.  it has a definite start and (usually) a definite end.  it comes with a sense of accomplishment when you’re done.  that’s nice.  kind of like… building a birdhouse or something.

anyway, the request was to compare a user’s home directory value to the user id to see if the user has the correct mapping.  sometimes while cloning accounts, this process may carry over something undesirable.  pretty simple stuff right?

let’s pretend you have a user named “Reimer Davies”.  his properties are as follows:

  • user id: “ReDavies”
  • home directory: \\myfileserver\redavies$

(yes, i know the mapping is old school home path.  this is what i had to deal with so bear with the example.  you can always change around the text manipulation statements to make it do what you want.)

anyway, here it is.  i wrote it (hopefully verbosely enough) for the requester to follow along.  all i did was split the home directory on the “\” and the “$” to get the exact user id out of it.  the user id itself was simple since it’s just as the value sits.  in the comparison, i dropped both to lowercases to processes it through.  your preference on whether you want to use if/then like i did or switch.  the best part was kicking it out to a custom object so i could push it into a gridview.  the reason this is cool is that i don’t have to write it once to kick out a list of “true” results and then later revise to kick out a list of “false” results.  you know how it goes.  sometimes you don’t know what you want until you see what you don’t want.

pushing it to gridview gives the requester the ability to sort and search as required (in 2.0).  anyway, let me know what you think.

# initialize a boring array for which we will push in user list information
$userListMatches = @()

$users = Get-QADUser -AccountExpiresAfter (Get-Date) -SearchRoot "ou=me,dc=mydomain,dc=com"

foreach ($user in $users) {
$hmdirtext = $user.homedirectory
$userid = $user.samaccountname

# break the user home directory into the user name only by splitting the \
$hmdir = $hmdirtext.split("\")[3]

# user name will still be user$ at this point so break the $ out
$hmdir = $hmdir.split("

# create a noteproperty object so we can use it with grid view
$myUserSet = New-Object System.Object

# add the values to the object
$myUserSet | Add-Member -type noteproperty -Name User -Value $userid
$myUserSet | Add-Member -type noteproperty -Name Home -Value $hmdirtext

# now compare the values
if ($hmdir.ToLower() -eq $userid.ToLower()) {
# add this value when the match is true
$myUserSet | Add-Member -type noteproperty -Name Matches? -Value "
} else {
# add this value when the match is false
$myUserSet | Add-Member -type noteproperty -Name Matches? -Value "

# add the userset value to the userlistmatches array
$userListMatches += $myUserSet

# now kick out the grid
$userListMatches | Out-GridView

Apr 14, 2010

using accountneverexpires with get-qaduser

if you’re trying to use the AccountNeverExpires parameter, you may not find the built-in help very forthcoming.  it specifies the use as:

Set the value of this parameter to 'true' if you want the cmdlet to retrieve only those user accounts that are configured to never expire.

i can tell you with confidence the following fails:

  • -accountneverexpires true
  • -accountneverexpires $true


so what works?

  • -accountneverexpires:$true


apparently, it requires a colon between accountneverexpires and $true.

Apr 12, 2010

behaviors with configmgr and supernets

i was forwarded a very useful blog post called “clarification on issues resulting from the use of supernets in configmgr 2007”.  if you need details, i urge you to read it.  this is just a summary of the post for my own benefit.

related blog posts:


site assignment / client push:

  • adsysdis writes ad site and ip subnet information to ddr
  • ddm compares ddr data against site boundaries
    • if ad site is in site boundaries, assigned = yes
    • if supernet is listed in site boundaries (directly), assigned = yes
    • client’s true subnet (non-supernet) listed in site boundaries, assigned = no


package source location:

  • client posts request to mp with the following:
    • package id
    • package version
    • assigned site code
    • ip address
    • calculated ip subnet
  • mp executes stored procedures to retrieve:
    • child secondary sites below assigned site
    • sites codes where ad site and/or ip address are assigned
  • mp then executes stored procedures to retrieve:
    • list of protected DPs
    • list of unprotected DPs
  • information is returned to client to process and determine best source