Forum / Remote Desktop Manager - PowerShell Repository

Change Users' Offline Mode

  • Create an Issue
  • Cancel

Hello,

Here's a script Function that will allow one to change Users Offline Mode. This function can be copied and saved to a .ps1 file, and use dot-sourcing to access the function.

Example: the file has been saved to c:\tools\SetUserCachingMode.ps1

From Remote Desktop Manager -> Tools -> PowerShell (RDM CmdLet)


. c:\tools\SetUserCachingMode.ps1

#either change a single user :
Set-RDMUserCachingMode -Name 'User' -CachingMode 'Disabled' #or any other available choice

#or change in bulk

Get-RDMUser | %{Set-RDMUserCachingMode -Name $_.name -CachingMode 'Disabled'} #or any other available choice

<###################
Function : Set-RDMUserCachingMode
Description : Change the Offline Caching Mode of a given User
Parameter : Name - The username of the user to change.
CachingMode - offline caching mode to set 'Disabled', 'Cache-Only', 'Read-Only', 'Read-Write'
Return : void
###################>
Function Set-RDMUserCachingMode{
Param(
[parameter(mandatory=$true)]
[string]$Name,

[parameter(mandatory=$true)]
[ValidateSet('Disabled', 'Cache-Only', 'Read-Only', 'Read-Write')]
[string]$CachingMode
)

if (-not (Get-Module RemoteDesktopManager.PowerShellModule)) {
Import-Module 'C:\Program Files (x86)\Devolutions\Remote Desktop Manager\RemoteDesktopManager.PowerShellModule.psd1'
}

#get the user by its name
$u = Get-RDMUser $Name
$xmlCustomSecurity = [xml]$u.CustomSecurity


# reset all settings to empty (as read-only)
if (($elem_to_del = $xmlCustomSecurity.CustomSecurity.ChildNodes | Where-Object {$_.Name -eq 'AllowOfflineEdit'}) -ne $null){
$xmlCustomSecurity.CustomSecurity.RemoveChild($elem_to_del)
}
if (($elem_to_del = $xmlCustomSecurity.CustomSecurity.ChildNodes | Where-Object {$_.Name -eq 'AllowOfflineMode'}) -ne $null){
$xmlCustomSecurity.CustomSecurity.RemoveChild($elem_to_del)
}
if (($elem_to_del = $xmlCustomSecurity.CustomSecurity.ChildNodes | Where-Object {$_.Name -eq 'AllowOfflineCaching'}) -ne $null){
$xmlCustomSecurity.CustomSecurity.RemoveChild($elem_to_del)
}

switch ($CachingMode)
{
'Disabled' {
$newElem = $xmlCustomSecurity.CreateElement('AllowOfflineCaching')
$newElem.InnerText = 'false'
$xmlcustomSecurity.customsecurity.AppendChild($newElem) | Out-Null
$newElem = $xmlCustomSecurity.CreateElement('AllowOfflineMode')
$newElem.InnerText = 'false'
$xmlcustomSecurity.customsecurity.AppendChild($newElem) | Out-Null
}
'Cache-Only'{
$newElem = $xmlCustomSecurity.CreateElement('AllowOfflineMode')
$newElem.InnerText = 'false'
$xmlcustomSecurity.customsecurity.AppendChild($newElem) | Out-Null
}
'Read-Only' {<# I leave it here in case #>}

'Read-Write' {
$newElem = $xmlCustomSecurity.CreateElement('AllowOfflineEdit')
$newElem.InnerText = 'true'
$xmlcustomSecurity.customsecurity.AppendChild($newElem) | Out-Null
}
}

$u.CustomSecurity = [string]$xmlCustomSecurity.OuterXml
Set-RDMUser $u

Write-Host "User" $u.Name "caching-mode is is now set to $CachingMode"
}

<###################
End of the function Set-RDMUserCachingMode
###################>

Hoping this makes your Users changes easier.



Alex Belisle

signaturesignature

Clock2 yrs