How to check if the user has not had an active session for more than 90 days and remove the license for these users?
I need to do this by PowerShell script.
Thank you for your help!
Hello,
To better assist you and ensure we're providing the most relevant support, could you please specify the type of data source you are currently using? At this moment, the functionality you are seeking is specifically available with a Devolutions Server data source through the Devolutions.PowerShell module. If you're using a different data source, I want to reassure you that we're committed to investigating how we can extend this functionality to meet your needs.
Best regards,
Maxime
Hello Maxime,
I using the Devolutions Server data source.
I tried using the Devolutions.PowerShell module but I was unsuccessful. I didn't understand from the documentation how to do it.
Best regards,
Ana
Hello Ana,
Here is an example using the DS cmdlets:
# Define variables
$username = "app id"
$pwd = ConvertTo-SecureString -AsPlainText "app secret"
$inactiveDays = 90
$serial = 'serial to look'
# Connect as an application
$creds = New-Object System.Management.Automation.PSCredential ($username, $pwd)
$baseURI = "your dvls url"
New-DSSession -Credential $creds -BaseUri $baseURI -AsApplication
# Find inactive users
$now = Get-Date
$userResponse = Get-DSUser
$inactiveUsers = $userResponse.Data | Where -Property LastLoginDate -ne $null | Where { (New-TimeSpan -Start $_.LastLoginDate -End $now).Days -gt $inactiveDays }
$inactiveUserIDs = $inactiveUsers | Select -ExpandProperty ID
# Get the license to unassign
$licResponse = Get-DSLicense
$lic = $licResponse.Data | Where -Property License -eq $serial
# Get the assignments of the inactive users
$assignmentsResponse = Get-DSUserLicense -InputObject $lic
$assignments = $assignmentsResponse.Data | Where -Property IsMember -eq $true | Where -Property UserId -in $inactiveUserIDs
# Unassign the license
foreach ($assignment in $assignments) {
$assignment.IsMember = $false
}
# Save the assigments
Set-DSUserLicense -InputObject $assignments
If you prefer to use RDM cmdlets, I will open a ticket to allow the license assignment on a Devolutions Server (DVLS) data source. Please feel free to reach out if you need further assistance or clarification on the example.
Regards,
Maxime
Hello Maxime,
Thank you for your help.
Can you give the same example using the RDM cmdlets?
Best regards,
Ana
Hello Ana,
Currently, it is not possible to assign users to a license with the RDM cmdlets.. I will open a ticket and keep updated when it will be done.
Best regards,
Maxime
Hello Maxime,
Do you have news for me?
Best regards,
Ana
Hello Ana,
The fix for the RDM cmdlets will be included in the next release, version 2024.1.0. I will provide you an exemple when it will become available later this week.
Best regards,
Maxime
Hello Maxime,
Thank you for the help.
To unlock it at this point, I saw that the Get-RDMLicense command returns the users object with all users assigned to a certain license. Will setting IsMember = false resolve the issue?
Another question is how can I get the user's last login date with RDM cmdlets. That is, replacing this part:
# Find inactive users
$now = Get-Date
$userResponse = Get-DSUser
$inactiveUsers = $userResponse.Data | Where -Property LastLoginDate -ne $null | Where { (New-TimeSpan -Start $_.LastLoginDate -End $now).Days -gt $inactiveDays }
$inactiveUserIDs = $inactiveUsers | Select -ExpandProperty ID
Best regards,
Ana
To unlock it at this point, I saw that the Get-RDMLicense command returns the users object with all users assigned to a certain license. Will setting IsMember = false resolve the issue?
Setting IsMember to $true will be the way to proceed. However, Set-RDMLicense ignores the assignments in DVLS data source. The upcoming fix will remediate this issue.
Another question is how can I get the user's last login date with RDM cmdlets.
The LastLoginDate property can be access like this: $user.UsreInfo.UserAccount.LastLoginDate
$now = Get-Date
$inactiveUsers = Get-RDMUser | Where { $_.UserInfo.UserAccount.LastLoginDate -ne $null } | Where { (New-TimeSpan -Start $_.UserInfo.UserAccount.LastLoginDate -End $now).Days -gt $inactiveDays }
Best regards,
Maxime
Hello Ana,
The fix has been included in the module version 2023.3.10 and 2024.1.0. Here is an example:
# Define variables
$inactiveDays = 90
$serial = 'serial to look'
# Find inactive users
$now = Get-Date
$inactiveUserIDs = Get-RDMUser | Where { $_.UserInfo.UserAccount.LastLoginDate -ne $null } | Where { (New-TimeSpan -Start $_.UserInfo.UserAccount.LastLoginDate -End $now).Days -gt $inactiveDays } | Select -ExpandProperty ID
# Get license to unassign
$lic = Get-RDMLicense -Serial $serial
# Unassign the license
$lic.Users | Where -Property UserId -in $inactiveUserIDs | ForEach-Object { $_.IsMember = $false }
# Save the modifications
Set-RDMLicense -License $lic
If you need more information, let us know.
Best regards,
Maxime
Tkank You Maxime,
I was testing, how can I validate that you got isMember = $false?
Hello Ana,
To validate that the unassignments worked as expected, you could add this at the end:
$lic = Get-RDMLicense -Serial $serial $unassignedUsers = $lic.Users | Where -Property UserId -in $inactiveUserIDs | Select -ExpandProperty IsMember $unassignedUsers -notcontains $true
It will return $true if all inactive users are unassigned.
Best regards,
Maxime
We recently purchased RDM Named users licenses and have setup autoassignement of these, which are working, and many users have a license now.
I have been trying to retrieve this through powershell, which im familiar with, but i have not used the Devolutions.PowerShell module before today.
We are using PowerShell 7.5.2 and Devolutions.PowerShell 2025.2.1 installed on the Devolutions Server.
Using
$lic = Get-RDMLicense -Serial $serial $lic.Users
Reports all users with "IsMember" equal to False. Do we need to have RDM installed for -RDM commands to work properly? (the docs said it was standalone now)
Using
$licResponse = Get-DSLicense $lic = $licResponse.Data | Where -Property License -eq $serial
Reports nothing as it does not have the .Data property. $licResponse lists the only (RDM) license we have directly, maybe if you have more than one license you get an array of licenses instead into a Data property?
$licResponse.Users is present but empty if comparing to the Get-RDMLicense result.
Using $licResponse directly instead of the empty $lic works
$assignmentsResponse = Get-DSUserLicense -InputObject $licResponse
Return all users and with the correct "IsMember" property, but it does not have the $assignmentsResponse.Data property.
Although we achieved what we needed, i wanted to give some feedback as this has quite frankly been a grueling exercise crawling through docs/forum, trying to find the correct method of connecting, finding out that permissions needs to be set for the application identity, and which commands to use.
We have not used application assignments before and wrongly assumed they came with the necessary permissions.
Why not mention it in one of the https://docs.devolutions.net/powershell/dvls-powershell/powershell-connectivity/ or https://docs.devolutions.net/server/web-interface/administration/security-management/applications/ which are the entry points when setting, instead of having to stumble over it in the bottom of https://docs.devolutions.net/hub/web-interface/administration/management/application-users/manage-application-users/.
Logs with debug on gave no meaningful errors when trying to perform actions with the application identity without permissions:
ArgumentNullException - Value cannot be null. (Parameter 'source')
at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable`1 source, Func`2 selector)
at Devolutions.Server.Controllers.APIControllers.V2.NotificationController.GetCurrentUserNotifications()
Best regards,
Lars
Hello Lars,
Reports nothing as it does not have the .Data property. $licResponse lists the only (RDM) license we have directly, maybe if you have more than one license you get an array of licenses instead into a Data property?
$licResponse.Users is present but empty if comparing to the Get-RDMLicense result.
Starting with module version 2024.2.0, the DS cmdlets now return the data field directly, so it's no longer necessary to access it via the .Data property.
Reports all users with "IsMember" equal to False. Do we need to have RDM installed for -RDM commands to work properly? (the docs said it was standalone now)
Regarding the RDM cmdlets: RDM does not need to be installed for them to function. Could you provide more details about the type of license that is causing the error? I haven’t been able to reproduce the issue on my end, so any additional information would be appreciated.
Although we achieved what we needed, i wanted to give some feedback as this has quite frankly been a grueling exercise crawling through docs/forum, trying to find the correct method of connecting, finding out that permissions needs to be set for the application identity, and which commands to use.
We have not used application assignments before and wrongly assumed they came with the necessary permissions.
Why not mention it in one of the https://docs.devolutions.net/powershell/dvls-powershell/powershell-connectivity/ or https://docs.devolutions.net/server/web-interface/administration/security-management/applications/ which are the entry points when setting, instead of having to stumble over it in the bottom of https://docs.devolutions.net/hub/web-interface/administration/management/application-users/manage-application-users/.
Thank you for your suggestion to improve our documentation — I’ve forwarded it to our documentation team.
Logs with debug on gave no meaningful errors when trying to perform actions with the application identity without permissions
I’ll also check whether we can improve the log output to better capture these scenarios.
Best regards,
Maxime
Hi,
Here are some info. Values in <> has been replaced by me.
PS C:\> Get-RDMDataSource
ID : <GUID>
IsConnected : True
IsOffline : False
Name : DVLS PowerShell
Type : RDMS
ID : <GUID>
IsConnected : False
IsOffline : False
Name : Local data source
Type : SQLite
PS C:\> $lic = Get-RDMLicense -Serial $serial
PS C:\> $lic
ActiveUsers : 85
Description : Remote Desktop Manager (Platinum Edition) <#> Users
EndDate : 31/07/2028
ID : <GUID>
IsAutoAssigned : True
License : <$serial>
MaximumUsers : <#>
OSC : <$serial>
Product : Remote Desktop Manager (Platinum Edition)
Status : Active
Users : {<Array of UserPrincipalNames>}
PS C:\> ($lic.Users | Where -Property IsMember -eq $True).Count
0
PS C:\> ($lic.Users | Where -Property IsMember -eq $False).Count
434
PS C:\> $lic.Users | Select -First 1
Description : <NAME>
HasActiveLicenseForSameProduct : False
IsAdministrator : False
IsMember : False
Name : <UserPrincipalName from AD>
Serial : <$serial>
UserId : <GUID>
Let me know if you need me to run any specific commands.
Best regards,
Lars
Hi Lars,
Thanks for the report. I was able to reproduce the issue and have implemented a fix. It will be included in the next release.
Appreciate your help in catching this!
Best regards,
Maxime
Hi Lars,
The fix is included in Devolutions.PowerShell version 2025.2.3, which has now been released. Thanks for your patience!
Best regards,
Maxime