Thursday, May 14, 2015

Get-DFSNFolderTarget

Hello! 

I been wondering how I can find out where a DFS target is through PowerShell for quite some time now, and perhaps I didn't look hard enough because today I found the cmdlet in the subject. 

Get-DfsnFolderTarget [-Path] <String> [[-TargetPath] <String> ] [-CimSession <CimSession[]> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]

It is a very handy command that will return the following output: 

PS Microsoft.PowerShell.Core\FileSystem::\\DFS\SHARE\PATH> Get-DfsnFolderTarget \\DFS\SHARE\PATH | fl *


Path                  : \\DFS\SHARE\PATH
State                 : Offline
ReferralPriorityClass : sitecost-normal
NamespacePath         : \\DFS\SHARE\PATH
ReferralPriorityRank  : 0
TargetPath            : \\targetServer\Share
PSComputerName        :
CimClass              : Root/Microsoft/Windows/dfsn:MSFT_DfsNamespaceFolderTarget
CimInstanceProperties : {NamespacePath, ReferralPriorityClass, ReferralPriorityRank, State...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

However, I have found it to be less than helpful if I don't know exactly 
where the DFS namespace ends and the targetPath begins, for example:

\\DFS\SHARE\PATH\Something\Folder 

If I try to find the root using this path I receive the following error:

Get-DfsnFolderTarget : Cannot get DFS folder properites on
"Microsoft.PowerShell.Core\FileSystem::\\DFS\SHARE\PATH\Something\Folder"
At line:1 char:1
+ Get-DfsnFolderTarget $((Get-Item .\).PSParentPath)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_DfsNamespaceFolderTarget:ROOT\Microsoft\...aceFolderTarget) [Get-Dfs
   nFolderTarget], CimException
    + FullyQualifiedErrorId : Windows System Error 1722,Get-DfsnFolderTarget

Get-DfsnFolderTarget : A general error occurred that is not covered by a more specific error code.
At line:1 char:1
+ Get-DfsnFolderTarget $((Get-Item .\).PSParentPath)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_DfsNamespaceFolderTarget:ROOT\Microsoft\...aceFolderTarget) [Get-Dfs
   nFolderTarget], CimException
    + FullyQualifiedErrorId : MI RESULT 1722,Get-DfsnFolderTarget

I am not sure why though. It is simple enough to get the information form the
GUI so perhaps is my inexperience or lack of knowledge, but why can't it be 
this easy on the cmd line as well?

I do hope that it is just my lack of knowledge and that maybe one of you
might show me the right way to get the DFSFolderTarget path. 

Kind regards, 
Me

No comments:

Post a Comment