DFSn links Operational readiness

‘Sup PSHomies,

So here is the follow up on the previous blog.

I recreated the shares, check! Now it’s time to create the DFSn Links & targets!

Here’s the code to create the necessary links and targets:

<#
Author: I. Strachan
Version:
Version History:
Purpose: Create DFS link with specified target
#>
[cmdletbinding()]
Param(
$csvFile = 'DFSnLinksTargets.csv'
)
Import-Module DFSN -Verbose:$false
#region Import
$csvDFSTargets = Import-Csv -Path .\sources\csv\$($csvFile) -Delimiter "`t" -Encoding UTF8
$DfsFolders = Get-DfsnRoot | ForEach-Object {Get-DfsnFolder -Path "$($_.Path)\*"}
#endregion
#region Main
foreach($dfs in $csvDFSTargets){
#Test if target exists first
if(!(Test-Path -LiteralPath $dfs.Target)){
Write-Warning "Target $($dfs.Target) doesn't exists"
Write-Verbose "Creating target $($dfs.Target)"
New-Item -Path $dfs.Target -ItemType Directory -Force
if(!($DfsFolders.Path -contains $($dfs.link))){
Write-Verbose "Creating $($dfs.link) with target $($dfs.Target)"
New-DfsnFolder -Path $dfs.Link -TargetPath $Dfs.Target
}
}
Else{
Write-Warning "Folder '$($dfs.Target)' already exists"
#Check if the DFS Target already exists
$CheckDFSTarget = Get-DfsnFolderTarget -Path $dfs.Link
if($CheckDFSTarget.TargetPath -eq $dfs.Target){
Write-Warning "DFSn Target is already set to $($dfs.Target)"
}
else{
Write-Verbose "Setting $($dfs.link) with target $($dfs.Target)"
Set-DfsnFolderTarget -Path $dfs.Link -TargetPath $dfs.Target
}
}
}
#endregion

Quick run down. The csv is straight forward Link, Target (tab delimited). I created a few checkpoints (again, better safe than sorry).First, I get a list of all actual DFS links & targets for reference. If the target doesn’t exist create it. That’s where the SMB share preparation came in 😉 If the link doesn’t exist create it. If the target exist, verify that it’s set to the specified link.

In my case I only have 1:1 Dfs link/target relationships. So this worked for me. Be sure to test this before trying it out in production.

I needed to recreate 1386 DFS links. This took a few minutes. 10 failed, not bad considering the amount. Now the old Irwin would have panicked at the sight of something going wrong (Whooosahhh). I kept it together and let script ride out. Once it was done I did my OVF to see which ones  failed 😉

<#
Author: I. Strachan
Version:
Version History:
Purpose: OVF DFS links & targets
#>
Param(
$csvFile = 'DFSnLinksTargets.csv'
)
Import-Module DFSN -Verbose:$false
#region Import CSV and saved Credentials
$csvDFSnTargets = Import-Csv -Path .\sources\csv\$($csvFile) -Delimiter "`t" -Encoding UTF8
$DfsnLinkTargets = Get-DfsnRoot |
ForEach-Object{
Get-DfsnFolder -Path "$($_.Path)\*" |
Get-DfsnFolderTarget |
Select-Object Path,TargetPath
}
#endregion
$lookupDFSn = $DfsnLinkTargets | Group-Object -AsHashTable -AsString -Property Path
#region Main
$csvDFSnTargets |
ForEach-Object{
Describe "DFSn Link & Target Operation validation share $($_.Link)" -Tags 'DFSnLinkTargets' {
Context "Verifying DFS Link $($_.Link)" {
It "DFS Link $($_.Link) exists" {
$lookupDFSn.$($_.Link).Path | Should be $_.Link
}
It "DFS Target $($_.Target) exists" {
$lookupDFSn.$($_.Link).TargetPath | Should be $_.Target
}
}
}
}
#endregion

This is one of those rare instances that I created the missing links by hand (don’t judge me I was on a tight schedule). Turns out a few had some form of a special character in the name. Creating them by hand didn’t raise an issue.

Last but not least I wanted to generate a ReportUnit HTML of the DFSn test results. Generating the ReportUnit HTML file didn’t go as I expected. It did succeed in the end., but generating a HTML report for 2772 was a bit too much. Having said that…

There’s a module for Formatting Pester result using PScribo created by Erwan Quélin. Definitely check it out if you want to do everything in PowerShell (Who doesn’t? :-P)

Usage is pretty easy:

dfsformatpesterps1

Here’s a quick screenshot of Format-Pester output:

dfsformatpester

Nice!

Once I resolved the failed test, I ran the test again, nothing but purple and green!

A quick notification in Slack using PSSlack by @pscookiemonster (Even though I’m the only one using Slack at the moment, give it time…)

Awesome!

So I learned that the size of the test when using ReportUnit.exe could be an issue, but if you want to do everything in PowerShell then Format-Pester is a better fit.

Hope it’s worth something to you

Ttyl,

Urv

Advertisement

3 thoughts on “DFSn links Operational readiness

  1. Pingback: Get DSA object creation date | pshirwin

  2. jkavanagh58

    Just FYI on your slack comment… I created a slack room focused on Powershell for my local area and I am always in the powershell.slack.com room.
    Really like your posts, will be adding to my Feedly stream!

    Liked by 1 person

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s