woreilly Posted August 25, 2015 Posted August 25, 2015 Hi all, I am in the process of developing a user creation script for my colleagues in powershell as our existing VBS script is just too slow. We use Domain based DFS Namespaces and I am trying to get my head around the DFS cmdlets available in Powershell. How can I detect an existing dfs namespace and use the detected path which I will then assign to the User's ProfilePath and HomeDirectory values? I am developing and testing currently on a 2012R2 machine. If I am too vague with my request, let me know!
woreilly Posted August 25, 2015 Author Posted August 25, 2015 Update: I have managed to get it to detect the dfs namespace and put it into a variable. However, it gives the FQDN in the path. Is there any advantage other than reducing the overall file path length to having it only put the NetBIOS domain name into the path? If so, how could I get it to output the NetBIOS name? Currently I have the following lines: $dfsroot = Get-DfsnRoot $dfspath = $dfsroot.Path $UsersPath = $dfspath + "\Users" With an example FQDN of "hogwarts.com" and DFS Namespace name of "hog", $UsersPath gives "\\hogwarts.com\hog\Users"
howartp Posted August 26, 2015 Posted August 26, 2015 $UsersPath = $UsersPath -replace "hogwarts.com" "hogwarts" I think? 1
woreilly Posted August 27, 2015 Author Posted August 27, 2015 (edited) Thank you @howartp. Your suggestion put me definitely on the right track. I now have it successfully using the netbios name instead of FQDN. Your suggestion of "-replace" didn't quite work. However, the following did: $UsersPath = $UsersPath.replace($dnsroot,$Netbios) FYI the full code for generating the dfs path is: $dnsroot = (GetADDomain).DNSRoot $Netbios = $Env:USERDOMAIN $dfsroot = Get-DfsnRoot $dfspath = $dfsroot.Path $UsersPath = $dfspath + "\Users" $UsersPath = $UsersPath.replace($dnsroot,$Netbios) If anyone out there has a solution which will do it in less lines then by all means give me a suggestion! Edited August 27, 2015 by woreilly
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now