Skip to content

Instantly share code, notes, and snippets.

@moddingg33k
Last active August 7, 2020 09:14
Show Gist options
  • Save moddingg33k/f2615fc1a1ff5636540496abb3ba0061 to your computer and use it in GitHub Desktop.
Save moddingg33k/f2615fc1a1ff5636540496abb3ba0061 to your computer and use it in GitHub Desktop.
Function Get-DfsnFolderTargetsRecursive
{
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $DFSPath
)
Write-Progress "Getting all DFS folders for $DFSPath (this can take a very long time)" -PercentComplete -1
$DFSTree = Get-DfsnFolder $DFSPath
$i = 1
$result = $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
return $result
}
Get-DfsnFolderTargetsRecursive '\\example.com\share' | Export-Csv "DFS-$(Get-Date -format yyyy-MM-dd).csv" -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment