Link to home
Start Free TrialLog in
Avatar of Alec Schrijver
Alec Schrijver

asked on

Create DFS Namespace with Powershell

I need to PowerShell script setup off DFS namespaces.
I've already scripted the creation of the folders and creating the share, but can't seem to work out how to script the DFS Namespace creation.
Can someone please help.

Domain: DomS3.local
Server: DomS3-DC1
Share Name: Test
Share target: c:\data\test

Many thanks,

Alec
Avatar of DevAdmin
DevAdmin
Flag of Italy image

Avatar of Alec Schrijver
Alec Schrijver

ASKER

Hi Ermanno

Many thanks for the links.
I have looked at these but can not figure out how to use them.
I tried new-dfsnroot -TargetPath \\doms3-dc1\test -Type DomainV2

Error:
Root target share \\doms3-dc1\test wasn't found. Namespace root target share should exist when creating new namespace
Thx for the suggestion, certainly sounded like a similar issue.
So i tried:

new-dfsnroot -targetpath \\doms3-dc1\test -type domainv2 -path \\dom3.local\test

error:
root target share "\\doms3-dc1\test" wasn;t found. Namespace root target share should exist when creating new namespace
try with fqdn name:

new-dfsnroot -targetpath \\doms3-dc1.dom3.local\test -type domainv2 -path \\dom3.local\test
A general error occurred that is not covered by a more specific error code.
but from the computer and with user that you use for excute the cmdlet you can open the share\\doms3-dc1.dom3.local\test in explorer?
This should help :

Create a DFS Namespace
For simplicity I’m going to create a DFS namespace called files in Windows Server 2012 R2. Theres only one file server (contososrv1) in my domain, and this will be where I install the DFS bits, and it will act as the namespace server. To configure and install the DFS namespace feature, log in to the file server with domain administrative privileges, open a PowerShell prompt and type the command below:
Install-WindowsFeature FS-DFS-Namespace

Open in new window


The file server currently has no shared folders, so I’m going to create three folders: sales, accounts, and production; and a folder for the namespace (DFS root), using the mkdir cmdlet. Note that you can use existing shared folders that are already populated with files.
$folders = (‘C:\dfsroots\files’,’C:\shares\sales’,’C:\shares\accounts’,’C:\shares\production’) 
mkdir -path $folders

Open in new window


Once the folders have been created, they need to be shared. The code below shares each folder using the New-SMBShare cmdlet, giving Everyone full access.
$folders | ForEach-Object {$sharename = (Get-Item $_).name; New-SMBShare -Name $shareName -Path $_ -FullAccess Everyone}

Open in new window


Now that the necessary folders and shares are in place, I can create the DFS namespace using the New-DfsnRoot cmdlet. \\ad.contoso.com\files is the UNC path for accessing the namespace, and \\contososrv1\files is used to specify the DFS root namespace server and path. The –Type parameter can be set to one of three values:
Standalone for a namespace that’s not integrated with Active Directory
DomainV1 for a Windows 2000 Server mode domain namespace
DomainV2 for a Windows Server 2008 mode domain namespace
For more information on the differences between standalone and domain-based namespaces, see Planning a DFS Architecture, Part 1 on the Petri IT Knowledgebase. Before selecting the DomainV2 mode, make sure that the forest-functional level is set to Windows Server 2003 or higher, the domain functional level is set to Windows Server 2008 or higher, and that all namespace servers are running Windows Server 2008 or later.

New-DfsnRoot -Path \\ad.contoso.com\files -TargetPath \\contososrv1\files -Type DomainV2

Open in new window


Finally, we need to add the folder targets to the namespace, i.e. sales, accounts, and production, which are separated from the DFS root in the shares folder. The code below adds each share to the files namespace:
$folders | Where-Object {$_ -like "*shares*"} | ForEach-Object {$name = (Get-Item $_).name; $DfsPath = (‘\\ad.contoso.com\files\’ + $name); $targetPath = (‘\\contososrv1\’ + $name);New-DfsnFolderTarget -Path $dfsPath -TargetPath $targetPath}

Open in new window


reference : https://www.petri.com/create-a-distributed-file-system-namespace-in-windows-server-2012-r2
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.