-1

I'm trying to format the output of this command to get only the dfsnamespace only like that :

\\F-TYPHON\DATA13\AI-Project

I can not use the Get-DfsnFolderTarget cmdlet because the RSAT-DFS-Mgmt-Con is not installed on all servers and I cannot install it .

$DFSPath="\\F-TYPHON\shared\AI-Project"

PS C:\> dfsutil client property state $DFSPath

Active, Online      \\F-TYPHON\DATA13\AI-Project

Done processing this command.

I've tried this .

PS C:\> $dfs=dfsutil client property state $DFSPath

PS C:\> $dfs.trimstart("Active, Online")

Method invocation failed because [System.Object[]] doesn't contain a method named 'trimstart'. At line:1 char:15 + $dfs.trimstart <<<< ("Active, Online") + CategoryInfo : InvalidOperation: (trimstart:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound

any help will be apreciated I can list all volume data for the filer but there's many incoherence in the structure so I need only to list the shared folder under "shared" on a filer and then procces it with dfsutil to get the absolut path

  • try doing `$dfs.GetType()` and `$dfs | Select-Object -Property *` so that you can see what is in the $Var ... and then choose the correct prop to use. [*grin*] i suspect you are looking at an array of strings instead of one long, multiline string. – Lee_Dailey Apr 22 '19 at 22:53
  • PS C:\> $dfs.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array here the output for the first – Wissem Rekaya Apr 22 '19 at 22:59
  • PS C:\> $dfs | Select-Object -Property * Length ------ 0 29 47 – Wissem Rekaya Apr 22 '19 at 23:00
  • so it is a _string array_, not a _string_. [*grin*] take a look at `Select-String` for ways to deal with that. – Lee_Dailey Apr 22 '19 at 23:39

2 Answers2

0

Use a regular expression to match the text output of dfsutil:

$DFSPath="\\F-TYPHON\shared\AI-Project"

if ((dfsutil client property state $DFSPath) -match "(?<=\s{2,})\\\\.*"){
   $DFSNameSpace = $Matches.Value
}
  • here (?<=\s{2,})\\\\.* matches two or more whitespace \s in a lookbehind
    followed by two (escaped) backslashes and the remainder of the line.
0

thank you for your help i've found a solution that i can use in a way it's not 100% powershell but i can use it to extract the output in a format that i can use it in a loop and than make automated robocopylines with powershell

here the code for the output that i found

$DFSPath="\F-TYPHON\shared\AI-Project"

$dfspath=(dfsutil client property state $DFSPath |findstr /i \F-TYPHON)|out-string

$dfs=$dfspath.Trimstart("Active, Online ")

write-host $dfs the output is

\F-TYPHON\DATA13\AI-Project

it's certainly not the best but i can work with it

if you have any others suggestion you're welcome