Friday, June 17, 2011

Adding users automatically to SAM database and then to VDI Console

While doing our project, we came to a position where we needed to have abt 40-50 users in SAM database and to add them using GUI would be a very lengthy process.

So we decided to use command prompt.

All you have to do is to create a .BAT file and add the following command to it.

net user (username) (password) /add /comment:"Test user, DELETE ME"
net user Rahul abcd /add /comment:"Test user, DELETE ME"

So, add the user names and passwords below one by one and run the bat file. All will be added.

To remove them, again create a .bat file and use this command.

net user Rahul /delete

So, we just created the file, added 20-30 lines with username and password and got them added to database.

Now to add users automatically, prepare a file with the names of users to be added to VDI Mgmt Console and then provide it as input in the script. One example of such script is:-

$fileinput=Get-Content 'C:\Users\zed\Desktop\input.txt'
foreach($i in $fileinput)
{
add-adminuser -DisplayName $i -UserName $i -DomainName localhost
}


For removing users from SAM database, you need to provide him the simple remove.bat file with remove command for all users and he can successfully remove all the user accounts.

Remove VHost from VDI

For this, the commandlet specified is:-
Remove-VHosts -Name -VirtualizationType -VirtualizationProductType

One can provide different virtualizationtypes and virtualizationproducttypes supported.

One example with image is:-

Delete DesktopCenter form VDI via Powershell

For deleting the Desktop Center, pscmdlet defined and used is:-
Remove-DesktopCenter -VirtualizationType -VirtualizationProductType -Name

A sample command with output is shown in image:-

Retrieving ManagedDesktops via Powershell

For retrieving the managed desktops, the pscmdlet provided by us is:-
Get-ManagedDesktops

This commands lists all the managed desktops available and returns the response object.
$x=get-manageddesktops
$x.listofMD
$x.listofMD.count

 

How to retrieve the list of MDPools

For this, the input parameter is DesktopCenter. According to particular datacenter, it will return the list of MDPools associated with it.

Method coded for this is:-
Get-MDPools -DataCenter (Provide here the datacenter)


To get the datacenter, use this command:-
Get-DesktopCenters -VirtualizationType (specify here) -VirtualizationProductType (Specify Here)

One example is:-
$x=get-desktopcenters -VirtualizationType parallels -VirtualizationProductType parallelscontainer
$y=get-mdpools $x.listofMDPool





How to retrieve DesktopCenters from VDI Management Console

First, go through this post about how to retrieve VHost.
http://automationofvdi.blogspot.com/2011/06/how-to-retrieve-vhosts-in-vdi.html

Now we have a pscmdlet for desktopcenter:-
Get-DesktopCenter -VirtualizationType -VirtualizationProductType

 Now for VirtualizationProductType, use get-VirtualizationProductType and for virtualizationType use get-VirtualizationType.

Now specify them in the particular order and you will get the DesktopCenters linked with it.

$x=Get-VirtualizationType
$y=Get-VirtualizationProductType
$x=Get-DesktopCentres $x[1] $y[1]


How to retrieve VHosts in VDI Management Console via Powershell


As per the code written by us, the pscmdlet for this is:-

Get-VHost -VirtualPlatform -VirtualizationProductType

So one can use this to get the VHosts.
For VirtualPlatform, we have created a method which gives the list of all the available VirtualizationPlatform that can be used and one can create an object of it and use that object as a parameter passed to the commandlet.

Get-VirtualPlatform

Similarly, for VirtualizationProductType we have the method

Get-VirtualizationProductType

So combined, we can use these to get the list of VirtualHosts. One example is:-

$x=get-virtualplatforms
$y=get-virtualizationproducttype
$z=get-vhosts -VirtualPlatform $x[0] -VirtualizationProductType $y[0]
$z.listofVH