Skip to main content

Updated : V0.992 Filesystem Powershell module

Update : version 0.992 now available including DFS-r

Hot on the heals of my AD sites module, I have been looking at some file system functions.  This module is driven primarily by my own needs, but after a prompt on the powergui website from someone after a way of managing DFS with powershell (thanks packetboy), this is what I have come up with.  All help files are included with examples, but I will publish the help and examples over time.


This module has been built on a Windows 2008 R2 platform and therefore the DFS functions will be based around the 2008 R2 version of DFSUTIL.  This is not to say that it is not compatible with anything earlier, it has just not been tested.
Installation and use

Download the zip file and extract to your modules folder. This can be found by running "explorer $pshome\modules" from a PowerShell console. To use, run "import-module Filesystem"

Command list and Help

To retrieve the list of commands and get help, as with all PowerShell functions and cmdlets use the built in get-command and get-help.

Get-command -module filesystem will list all the commands from the module

Get-help get-dfsroot -full will display the full help file

Included functions 


Please let me know any feedback in the comments, and of course, test in a development environment before using in production.

The module can be downloaded here.




  1. Thanks. Just what I was looking for. Works nicely.

  2. This is really really useful thank you. One comment though - it appears from my early testing that since you're picking up the $env:USERDOMAIN value and referencing it as $netbiosdomain, then using that as a reference on the "object" parameters for adding / removing NTFS permissions, you can't specify for example, the builtin\users group to act upon?

  3. having said that, commenting out the $userdomain argument and its comma within the argumentlist parameter of the ntaccount class does the trick, just means you need to specify the domain as part of the -object parameter

  4. thanks for the feedback. I will update the functions to allow for built in groups to be added.


  5. Me again - Following your lead, I've created equivalent DFSR functions to create replication groups, add members, add connections, add folders etc. Not quite as elegant as your DFSN / file services module but if you want the code to add to your module or to update and publish as you see fit, you're welcome to it, after all the work you saved me by making your module available.

  6. Thank you, works very well, the only way I found to get a decent formatting when listing DFS targets. You might consider changing the module-name from filesystem to something more unique, I already had another module named filesystem, I suspect it is common.

  7. What I've seen so far is awesome, however the get-dfslink cmdlet doesn't return the entire link name when it contains a space (I inherited it, and I'm not the senior SysAdmin...)
    Thank you,

  8. Actually the Get-DFSLink cmdlet doesn't seem to like spaces either. It seems to be returning the correct information, but it throws a "You cannot call a method on a Null-Valued Expression" error for each space in the path, even when encased in single or double quotes.
    On the plus side, it is handling the ridiculous number of "&" characters like a champ (I have a single path with 4 '&' Characters)!

  9. A minor thing, for anyone doing the wierd things I am, Get-DFSLink seems to return a Hash or Array for the Targets, which is fine, however, the 'State' Property of the Targets Noteproperty for a disabled Target is returned as "disbled" so, if like me you are filtering out disabled targets, make sure you are checking for "disbled". It might be good to note that I think I'm using Version .95 not .94

  10. Thanks for the great feedback, I'll update in the next couple of days.

  11. anon - where can we get the DFSr files you made?

  12. Another big thank you for this useful module. Can I suggest you rename Process-FixedWidthText to Format-FixedWidthText to get rid of the unapproved verb warning.

  13. Hopefully you are still active on this blog. I'm using your module, and I'm very happy so far, but I cannot figure out how to return, all the namespace server of a specific name space.

    Can you help ?

    1. Seems that you have found a bug....the get-dfsroot command should output the namespace servers in the targets attribute.

      Thanks for the feedback :)


Post a Comment

Popular posts from this blog

PowerShell 3 behavioural change

It's taken me way too long to get into PowerShell 3, I guess opportunity hasn't shown it's self until now and so, here, my V3 journey begins.

I was asked to debug a script that would run fine in PS v2 and not in v3.  The issue was a that a variable length was being checked and was failing in v3.  This is why...

In v2 if a variable is undefined, this test returns false

PS C:\windows\system32> $var.length -eq 0

In v3 the same test returns true....

PS C:\windows\system32> $var.length -eq 0

Not a biggie, but as in this case, a script has broken so something to consider!



Enable Powershell Remoting (WinRM) via Group Policy

I have been doing some testing on enabling WinRM via group policy, being that WinRM is the service that Powershell v2 sets up it remoting capabilities. Here are the GPO settings that you need to configure WinRM ....

set the winrm service to auto start

Computer Configuration \ Policies \ Windows Settings \ Security Settings \ System Services

Windows Remote Management (WS-Management)  set Startup Mode to Automatic

start the service

incorporated in to the above - you may need a restart.

create a winrm listener

Computer Configuration / Policies / Administrative Templates / Windows Components / Windows Remote Management (WinRM) / WinRM Service / Allow automatic configuration of listeners

IPv4 filter: *

* is listen on all addresses, or if you only want a particular IP address to respond use an iprange eg - don't forget that this IP range has to be valid for all hosts that fall in the scope of the GPO you are creating.  You can use -, - …

compare-object in Powershell - comparing mulitple values

I'm starting to use compare-object more and more, and one thing I noticed, is that you can compare 2 objects based on multiple attributes. here is how it is constructed...
Compare-Object -ReferenceObject $object1 -DifferenceObject $object2 -Property a,b,c,d,eIf a,b,c and d are the same, but e is different, compare object will return a difference. In the following example, I use "-eq $null" as a check because by default compare-object returns $null if the objects are the same.
#create an array of objects to check against

$collection = @()
foreach ($entry in ("aaaaa","bbbbb","ccccc","ddddd")){
   $store = "" | select "a","b","c","d","e"
   $store.a = $entry*1
   $store.b = $entry*2
   $store.c = $entry*3
   $store.d = $entry*4
   $store.e = $entry*5
   $collection += $store

#create an object similar to those in the array
$object = "" | select "a","b…