{"id":4131,"date":"2016-02-04T16:16:35","date_gmt":"2016-02-05T00:16:35","guid":{"rendered":"http:\/\/www.atumvirt.com\/?p=4131"},"modified":"2016-02-04T16:16:35","modified_gmt":"2016-02-05T00:16:35","slug":"adding-rds-assigned-virtual-desktop-user-to-scvmm","status":"publish","type":"post","link":"https:\/\/avtempwp.azurewebsites.net\/2016\/02\/adding-rds-assigned-virtual-desktop-user-to-scvmm\/","title":{"rendered":"Adding RDS Assigned Virtual Desktop User to SCVMM"},"content":{"rendered":"

When working with RDS VDI scenarios using VMM, it may be helpful to have a view of which users are assigned to persistent desktops.\u00a0 Using the extensible power of Virtual Machine manager, you can easily provide this information to all of your virtual machines.\u00a0 The script below can be run on a schedule to keep this data in sync or as part of an automation workflow.<\/p>\n

First, you must prepare the property you will use.<\/p>\n

Import-Module VirtualMachineManager\n\nNew-SCCustomProperty -Name \"RDUser\" -AddMember @(\"VM\")<\/pre>\n

Once this has been done, schedule\/run the following script manually<\/p>\n

Import-Module RemoteDesktop,VirtualMachineManager\n$broker= \"RDBroker.Contoso.com\"\n$VMMServer=\"SCVMM.Contoso.com\"\n$Deployment = Get-RDRemoteDesktop -connectionBroker $broker\n$RDUserProperty=Get-SCCustomProperty -Name \"RDUser\"\u00a0 #We need an object that represents the property \"RDUser\"\n\n#Get the RD Persistent Assignments\n$RDPVDA= Get-RDPersonalVirtualDesktopAssignment -collectionName $Deployment.CollectionName -connectionBroker $broker\n\nforeach ($entry in $RDPVDA)\n{\n#First we get the VM we want to work with, set variable to null prior to starting work to avoid working on old resources\n$vm = $null\n$vm = get-VM $entry.VirtualDesktopName -VMMServer $VMMServer\n#Now we set it!\nSet-SCCustomPropertyValue -inputobject $vm -customproperty $RDUserProperty -value $entry.user\n}\n\n <\/pre>\n

Once completed, you\u2019ll be able to customize your view to see this property (right click the column headers to add another)<\/p>\n

\"VMM-CustomProperty\"<\/a><\/p>\n

 <\/p>\n

This can also be done for POOLED desktops, but this version does not remove users once they\u2019ve logged off.\u00a0 More tinkering is needed to fix that.\u00a0 One method is to blank all settings in the VMs, but that requires significant filtering.\u00a0 The downside as well is it generates a lot of jobs, and despite the documentation, -JobGroupID is not supported on the Set-SCCustomPropertyValue cmdlet.<\/p>\n

 <\/p>\n

\nImport-Module RemoteDesktop,VirtualMachineManager\n$broker= \"RDBroker.Contoso.com\"\n$VMMServer=\"SCVMM.Contoso.com\"\n$Deployment = Get-RDRemoteDesktop -connectionBroker $broker\n$RDUserProperty=Get-SCCustomProperty -Name \"RDUser\"\u00a0 #We need an object that represents the property \"RDUser\"\n\n#Get the RD Persistent Assignments\n$RDPVDA= Get-RDPersonalVirtualDesktopAssignment -collectionName $Deployment.CollectionName -connectionBroker $broker\n\nforeach ($entry in $RDPVDA)\n{\n#First we get the VM we want to work with, set variable to null prior to starting work to avoid working on old resources\n$vm = $null\n$vm = get-VM $entry.VirtualDesktopName -VMMServer $VMMServer\n#Now we set it!\nSet-SCCustomPropertyValue -inputobject $vm -customproperty $RDUserProperty -value $entry.user\n}\n\n#Now we move on to pooled\n#Get sessions, Filter out Shared sessions, only getting pooled VDI\n$Sessions=Get-RDUserSession -connectionBroker $Broker | Where-object {$_.CollectionType -eq \"RD_FARM_TEMP_VM\" }\nforeach ($session in $sessions)\n{\n$vm = $null\n$VMBaseName=$null\n#Split the name into a usable string\n$VMBaseName=$session.servername.Split(\".\")[0]\n$vm=Get-VM $VMBaseName -VMMServer $VMMServer\n#Now we set it!\nSet-SCCustomPropertyValue -inputobject $vm -customproperty $RDUserProperty -value $Session.UserName\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"

When working with RDS VDI scenarios using VMM, it may be helpful to have a view of which users are assigned to persistent desktops.\u00a0 Using the extensible power of Virtual Machine manager, you can easily provide this information to all of your virtual machines.\u00a0 The script below can be run on a schedule to keep […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[82,33,63],"tags":[],"_links":{"self":[{"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/posts\/4131"}],"collection":[{"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/comments?post=4131"}],"version-history":[{"count":0,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/posts\/4131\/revisions"}],"wp:attachment":[{"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/media?parent=4131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/categories?post=4131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avtempwp.azurewebsites.net\/wp-json\/wp\/v2\/tags?post=4131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}