The goal of this page is to describe an example of workflow used in my company with this posershell module (in version 2).
The requirements where the following
1. We need to configure completly DatAnywhere for users, because they probably don't have the required knowledge to do it by themselves.
2. Users have a personnal home directory shared on the DFS as \domain\dfs\users\samaccountname
3. Users have access to their home dir in view only mode (no offline synchronisation) in DatAnywhere
4. A subfolder "sync" of the home directory can be fully synchronised and available read/write in DatAnywhere
5. A subfolder "Envoi" (=send) of the folder "sync" allow users to send files using DatAnywhere
6. A subfolder "Reception" (=receive) of the folder "sync" allow users to receive files from other people using DatAnywhere
Unfortunetaly, the "view only" and the 'stub" modes are only configurable by root in DN, and not by folder. And you cannot add two roots with the same path. So we had to trick DN by creating two entries in our DFS that points to the same folder:
\domain\dfs\users
\domain\dfs\homedir
So first step was to create a root in view only mode. We created it manualy, because we need it only once. For references the command look like:
Add-DatAnywhereRoot -RootName HomeDir -UNCPath \\domain\dfs\users -IncludeNested -PreviewOnly
Once this first root is created, we can run ou workflow:
First connect to DN.
Connect-DatAnywhereServer -DatAnywhereServer Server1 -Username my_user -Password my_pass
Get the Root Home.
$RootHome = Get-DatAnywhereRoot -UNCPath "\\domain\dfs\users"
if ($RootHome -eq $null) { Throw "Root home does not exists !" }
Then start a loop for each users to configure. This loop does the following:
$TargetUserAccount = sam_account_name_of_user
$HomeFolder = "\\domain\dfs\HOMEDIRS\$TargetUserAccount"
Create the folders in the HomeDir of the user.
$null = New-Item -ItemType directory -Path "$HomeFolder\Sync"
$null = New-Item -ItemType directory -Path "$HomeFolder\Sync\Envoi"
$null = New-Item -ItemType directory -Path "$HomeFolder\Sync\Reception"
To avoid that the users delete these folders in its HomeDir, we added a deny delete in NTFS for these 3 folders.
Add-NTFSAccess -Account DOMAIN\$TargetUserAccount -AccessRights Delete -AccessType Deny -AppliesTo ThisFolderOnly -Path "$HomeFolder\Sync"
Add-NTFSAccess -Account DOMAIN\$TargetUserAccount -AccessRights Delete -AccessType Deny -AppliesTo ThisFolderOnly -Path "$HomeFolder\Sync\Envoi"
Add-NTFSAccess -Account DOMAIN\$TargetUserAccount -AccessRights Delete -AccessType Deny -AppliesTo ThisFolderOnly -Path "$HomeFolder\Sync\Reception"
Create the root for the sync folder of the user. Remember as this one is not view only, we needed a new root. This new root must be per user, otherwise, they would have full stub access to their complete HomeDir.
$Root = Add-DatAnywhereRoot -RootName Sync -UNCPath "$HomeFolder\Sync" -IncludeNested -IsStub
Edit the collaboration parameters on the sub folders Envoi and Reception
$null=Set-DatAnywhereSharedFolder -Root $Root -FolderPath "Envoi" -DownloadEnabled
$null=Set-DatAnywhereSharedFolder -Root $Root -FolderPath "Reception" -UploadEnabled
Create the private workspace of the user
$objWorkspace=Add-DatAnywherePrivateWorkspace -Name "Espace Personnel" -TargetUserAccount "DOMAIN\$TargetUserAccount"
Add the folders in the Workspace.
For this wee need first to create an array of "Worspace Folder" objects. Indeed, there is no command such as add folder or remove folder in a workspace. Each time you want to change the content of a workspace, you need to set the list of folder. So to add or remove a folder, just generate and updated list of folder and set it in the workspace.
If the list is empty, the workspace all folders will be removed from the workspace.
Note also that I was not able to find an API (an admin one) that list the folder presently configured in a workspace. So you need to have another way to know this information when you want to modify a workspace.
Create the folder objects array:
$WksFolders = @()
First we add the subfolder "sam_account_name" from the HomeDir Root.
$WksFolders += $RootHome | New-DatAnywhereWorkspaceFolder -Name "$TargetUserAccount (HomeDir)" -PathFromRoot $TargetUserAccount
Then we add the Sync Root of the user, with no subfolder.
$WksFolders += $Root | New-DatAnywhereWorkspaceFolder -Name Sync
Finaly, we set these folders into the workspace.
Set-DatAnywhereFolderInPrivateWorkspace -Workspace $objWorkspace -WorkspaceFolder $WksFolders
That's it for the loop.
Note that the list of users is managed by an Active Directory group.
Each time a user is added into the AD group that gives access to DatAnywhere, the script detects it (script runs twice a day) and perform the configuration.
If a user is removed from the AD group, the delete loop is triggered:
$HomeFolder = "\\domain\dfs\HOMEDIRS\$TargetUserAccount"
Remove Workspace.
Get-DatAnywherePrivateWorkspace -TargetUserAccount "DOOMAIN\$TargetUserAccount" -Name "Espace Personnel" | Remove-DatAnywherePrivateWorkspace
Get Root Sync of user
$Root = Get-DatAnywhereRoot -UNCpath "$HomeFolder\Sync" -ErrorAction SilentlyContinue
Remove collaboration parameters (same command as for configuration, but no configuration switches)
Set-DatAnywhereSharedFolder -Root $Root -FolderPath "Envoi"
Set-DatAnywhereSharedFolder -Root $Root -FolderPath "Reception"
Remove Root
Remove-DatAnywhereRoot -Root $Root
Remove user from DN
Get-DatAnywhereUser -UserAccount $TargetUserAccount | Remove-DatAnywhereUser
This last command is dangerous if you have users with the same First Name and Last Name, because the DN API used return only DN userID and DN userName. There is no link with the AD account or AD SID. So when you search a user by its account, the string "First Name, Last Name" is gathered from the AD and then the user is searched n DN with this value.
EDIT : I just saw that using another API wolud have better results. Created a ticket.
I hope this example will help you to create your own workflows.