Windows 365 is automatically deprovisioned after 30 days of inactivity.

Кирилл Миронов 0 Reputation points
2024-04-08T11:22:52.91+00:00

We use VDI and noticed that many employees do not use them or never connect. We would like to configure it so that 30 days after the VDI workstation is not used it will automatically be deprovisioned

Windows 365 Business
{count} votes

1 answer

Sort by: Most helpful
  1. ZhoumingDuan-MSFT 8,060 Reputation points Microsoft Vendor
    2024-04-09T02:01:33.7866667+00:00

    @Кирилл Миронов,Thanks for posting in Q&A.

    To automatically delete an Azure VDI machine when a user has not logged in for 30 days, you can use Azure Automation and a PowerShell script. Here are the high-level steps:

    Create an Azure Automation account in your Azure subscription.

    Create a new PowerShell runbook in the Azure Automation account.

    Write a PowerShell script that checks the last login time for each user on the VDI machine and deletes the machine if no user has logged in for 30 days.

    Schedule the PowerShell runbook to run on a regular basis (e.g., daily) using a recurring schedule in Azure Automation.

    Here is an example PowerShell script that you can use as a starting point:

    $vmName = "MyVDIMachine"

    $daysToKeep = 30

    $lastLogon = (Get-WmiObject -Class Win32_UserProfile -ComputerName $vmName | Select-Object -Property LastUseTime | Measure-Object -Property LastUseTime -Maximum).Maximum

    $daysSinceLastLogon = (New-TimeSpan -Start $lastLogon).Days

    if ($daysSinceLastLogon -gt $daysToKeep) {

    Remove-AzVM -ResourceGroupName "MyResourceGroup" -Name $vmName -Force
    

    }

    This script uses the Get-WmiObject cmdlet to retrieve the last login time for each user on the VDI machine, calculates the number of days since the last login, and deletes the machine if no user has logged in for 30 days.

    Note that you will need to modify the script to use the appropriate Azure PowerShell cmdlets for your environment and to specify the correct resource group and VM name.

    Hope it will help.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.