-
-
Save markwragg/0900550dc3951c2f44433f6f9225f7aa to your computer and use it in GitHub Desktop.
$Servers = @("SERVER01","SERVER02","SERVER03") | |
$FolderPaths = $Servers | foreach { | |
Get-ChildItem "\\$_\DFSShare$" | |
} | Sort Path | |
$FolderPaths | Export-Csv "FolderPaths-$(Get-Date -format yyyy-MM-dd).csv" -NoTypeInformation | |
$TestPaths = (($FolderPaths).FullName | Sort-Object).Trimend('\') | |
$DFSPaths = ((Import-CSV "DFS-$(Get-Date -format yyyy-MM-dd).csv").TargetPath | Where-Object {($_ -ilike "*SERVER*") | Sort-Object).Trimend('\') | |
$TestPaths | Where-Object {$DFSPaths -notcontains $_} |
[CmdletBinding()] | |
param( | |
$DFSPath #Example:= '\\example.com\folder\*\whatever' | |
) | |
Write-Progress "Getting all DFS folders for $DFSPath (this can take a very long time)" -PercentComplete -1 | |
$DFSTree = Get-DfsnFolder $DFSPath | |
$i = 1 | |
$DFSTree | ForEach-Object{ | |
Write-Progress "Getting DFS Folder Targets for $($_.Path)" -PercentComplete (($i / $DFSTree.Count) *100) | |
$DFSTarget = Get-DfsnFolderTarget $_.Path | Select Path,TargetPath,State | |
$Result = [ordered]@{ | |
Path = $DFSTarget.Path | |
TargetPath = $DFSTarget.TargetPath | |
State = $DFSTarget.State | |
"ValidFrom_$Env:ComputerName" = Test-Path $DFSTarget.Path | |
} | |
New-Object PSObject -Property $Result | |
$i++ | |
} | Sort Path | Export-Csv "DFS-$(Get-Date -format yyyy-MM-dd).csv" -NoTypeInformation |
if my dfs folder has 3 path (more than one) I get "System.Object[]","System.Object[]","System.Object[]","System.Object[]"
log:
"\\mydomain\dfs1\folderA","\\server5\share$\folderA","Online","True"
"\\mydomain\dfs1\folderB","\\server5\share$\folderB","Online","True"
"System.Object[]","System.Object[]","System.Object[]","System.Object[]"
"\\mydomain\dfs1\folderD","\\server7\share$\folderD","Online","True"
"System.Object[]","System.Object[]","System.Object[]","System.Object[]"
"System.Object[]","System.Object[]","System.Object[]","System.Object[]"
"\\mydomain\dfs1\folderG","\\server5\share$\folderG","Online","True"
"\\mydomain\dfs1\folderH","\\server6\share$\folderH","Online","True"
example:
Get-DfsnFolderTarget \\mydomain\dfs1\folderC
Path TargetPath State ReferralPriorityClass ReferralPriorityRank
\\mydomain\dfs1\folderC \\server5\share$\folderC Online sitecost-normal 0
\\mydomain\dfs1\folderC \\server6\share$\folderC Online sitecost-normal 0
\\mydomain\dfs1\folderC \\server7\share$\folderC Online sitecost-normal 0
To address the issue reported by @kamiltitera I forked the gist and made the script iterate through each destination when an array is returned. Unfortunately, gists don't have pull request support, so the author @markwragg would need to review the code and see if it is something he wants to manually commit.
The proposed change can be found here: https://gist.github.com/justpowershell/488f8c6936dfb7be8178e337cebaa250
@justpowershell your forked version works like a charm. It should definitely be added to the main script.
@markwragg I see that this has been dormant for a bit, but I just stumbled across it, and hope it might be what I am looking for. I have a large DFS structure, but it is a mess. I am trying to find all of the locations where we have a \home\ and then a user account folder in my structure.
Could I use this for something like that. Basically, we have been going through a lot of turnover and I just got a list of almost 250 users that have left the organization, and I need to remove their home directories, unfortunately, the previous regime didn't believe in using the AD homedirectory field, so I have no clue where the home directories might live, besides, "They are in DFS". Can i use your script to spit out all of the folders in my DFS and filter out the home directories?
app
This script only works for a single target. I fixed it to work with multi-value properties.
[CmdletBinding()]
param(
$DFSPath = '\DFSNamespace*'
)
Write-Progress "Getting all DFS folders for $DFSPath (this can take a very long time)" -PercentComplete -1
$DFSTree = Get-DfsnFolder $DFSPath
$i = 1
$DFSTree | ForEach-Object{
Write-Progress "Getting DFS Folder Targets for $($_.Path)" -PercentComplete (($i / $DFSTree.Count) *100)
$DFSTarget = Get-DfsnFolderTarget $_.Path | Select Path,TargetPath,State
$Result = [ordered]@{
Path = $DFSTarget.Path
TargetPath = $DFSTarget.TargetPath
State = $DFSTarget.State
"ValidFrom_$Env:ComputerName" = Test-Path $DFSTarget.Path
}
New-Object PSObject -Property $Result
$i++
} | Sort Path | Select @{Name='Path';Expression={[string]::join(";", ($."Path"))}}, @{Name='TargetPath';Expression={[string]::join(";", ($."TargetPath"))}},@{Name='State';Expression={[string]::join(";", (
I know this is dated...but I thought I'd add what I've done:
Here's what
$namespaces = Get-DfsnRoot -Domain domain.com
foreach ($ns in $namespaces){
#$ns.Path
#Get
$DFSPath
$DFSNFolders = Get-DfsnFolder $DFSPath
foreach($DFSNFolder in $DFSNFolders )
{
$DFSTarget = Get-DfsnFolderTarget $DFSNFolder.Path | Select Path,TargetPath,State
$DFSTarget|Export-Csv "DFS.csv" -NoTypeInformation -Append
}
}
Hi Shackdan,
your Script created an empty file.
Perhaps you don't have access to the DFS namespace.
You can verify by simply running "Get-DfsnRoot -domain [domain.com]"
@JoeAlvis81
For some reason i get empty cells as output shown below:
#TYPE Selected.System.Management.Automation.PSCustomObject | ||
---|---|---|
Path | TargetPath | State |
Online | ||
Online | ||
Online | ||
Online | ||
Online | ||
Online | ||
Online | ||
Online | ||
Online |
This one worked
$namespaces = '\domainns\x*'
foreach ($ns in $namespaces)
{
$DFSNFolders = Get-DfsnFolder -path $ns
foreach($DFSNFolder in $DFSNFolders )
{
$dfs=$DFSNFolder.Path
$DFSTarget = Get-DfsnFolderTarget $DFS | Select Path,TargetPath,State
$DFSTarget|Export-Csv "DFS.csv" -NoTypeInformation -Append
}
}
I get one or more parameter values passed to the method were invalid in the line $DFSNFolders = Get-DfsnFolder -path $ns
Alanmckeon - To fix the error add a \ in the path
Wrote an improved function
https://gist.github.com/laymanstake/4a16bdda8c7ad94c5bdfe734892dcf4e
Thanks for this. Very helpful.