Showing posts with label XENServer. Show all posts
Showing posts with label XENServer. Show all posts

Friday, June 14, 2013

Join VSC Created Linked Clones to a Domain

By:Rik Hoffelder

Overview
One of the features of using Citrix's VSC with XenServer and NetApp storage is to take advantage of linked clones. The benefits of doing this are very rapid virtual desktop provisioning while consuming very little storage. When the process is run it doesn't have the ability to name the VM or join it to an Active Directory domain. Rather the machines are created with the typical Microsoft naming standard of some very long unusable name, even though the VM is labeled correctly in the XenCenter console. You could of course manually rename and join each machine to the domain, which is fine if you created just a few. But what if you just created 200? Wouldn't a nice PowerShell script help solve that problem for you? Of course it would, so I wrote one to help one of my customers do just that. Because I'm a nice guy who wants to give back to all those bloggers who have helped me by sharing their knowledge, here it is for you!

One of the major challenges in a script like this is finding the right machine to rename. Remember, as I noted above the machine is labeled in XenCenter correctly, but the actual name in the operating system is completely different. Because of this we need to use the IP address of the newly created VM in order to connect with PowerShell remotely to perform the rename and domain join process. In order to get that information from the VM we would need to know its real name, right? Not with the XenServer cmdlets for PowerShell. With this little toolset I can extract the IP address based on the VM label, not its actual name.

The script is designed to operate on PowerShell 3.0 in order to take advantage of improvements in remote management that doesn't require a lot of security changes and extra configuration to establish the remote session. In fact PowerShell 3.0 offers the capability of performing the VM rename and domain join in a single cmdlet with a single reboot, so it runs much faster than with PowerShell 2.0 that required two separate operations with two reboots to perform the same task.
Obviously the script requires the PowerShell cmdlets for XenServer. So you'll want to download that from here. Now because Citrix does a poor job of documenting the SDK, you'll need this article to help you register the Snapin with PowerShell.

Script Facts
In my script I use a temporary CSV file to build a list of VMs based off the user's input in the GUI. I then run a Foreach loop to process each VM from that CSV file. So make note, you'll either need to modify the script to use your own path or create a C:\TEST directory to store the CSV. The script also creates an import file named oddly enough, IMPORT.CSV in that same directory. The IMPORT.CSV file builds a list of the new VMs so that you may import them into a catalog in XenDesktop. Hey I tried to make this easy!

To run the script you must start PowerShell with elevated rights. In other words it must Run as Administrator from the management computer with the XenServer cmdlets installed and registered. This is a requirement to support the remote calls to the VM using PowerShell 3.0.
There are also a few places you'll need to edit the script to customize it for your environment. First, I create a dropdown menu of target OU aliases so the admin using the script doesn't have to remember a long distinguished name. So you will need to find the following section and update it to match your need:
    
[array]$OUs = "Windows 7 Admin OU - CORP Domain",
"Windows 7 OU - CORP Domain" <-NO COMMA HERE!!

Be sure to include the alias name in quotation marks "Alias" followed by a comma. The last line should not be followed by a comma as noted above.
Next you will need to locate this section to map the alias selected in the dropdown menu to the actual OU path. Update the items highlighted in red below to match your environmental need.
$OUPath = $Combobox.SelectedItem.ToString()

 
If ($OUPath -eq "Windows 7 Admin OU - CORP Domain"){
$OUPath = "OU=Win 7 Dedicated Admin,OU=Virtual Desktops,OU=Workstations,DC=CORP,DC=COM"
}
If ($OUPath -eq "Windows 7 OU - CORP Domain"){
$OUPath = "OU=Win 7 Dedicated,OU=Virtual Desktops,OU=Workstations,DC=CORP,DC=COM"
}


Last but not least, to build the import file you will need to know the connection string used by XenDesktop. To get that connection string you will need to perform an export from an existing catalog. Use this Citrix article as a reference if you aren't familiar with catalog export. Open the export file and use the data highlighted below:
 
  
To replace the value highlighted in red in the code snippet below:
        ### Build XD Catalog Import CSV ###
Write-Host "Building XenDesktop Import CSV"
$XDCsvHeader = "[VirtualMachinePath],[ADComputerAccount],[AssignedUsers]"
$XDConnectBase = "XDHyp:\connections\PVS Task Pool\"


Running the Script
That's it, you are not ready to kick the tires and give it a try. After launching the script a PowerShell-based GUI will open. Complete all of the fields and then click OK.
 

  
You will be prompted to enter the credentials of a user with rights to join machines to the domain:
           
                                                       

 
After clicking OK you will be prompted for the credentials of the local administrator for the VM. This is used to access the VM using PowerShell remoting.

                                     
           
Once you click OK the script takes off and does its thing. When the script has completed it will notify you that the IMPORT.CSV file is ready for import. That's it, enjoy!

Join-Domain:XD.PS1
function
Show-MessageBox ($title, $msg) {

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") |
Out-Null


[Windows.Forms.MessageBox]::Show($msg, $title,
[Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information,
[System.Windows.Forms.MessageBoxDefaultButton]::Button1,
[System.Windows.Forms.MessageBoxOptions]::DefaultDesktopOnly) |
Out-Null

}

 
[void]
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

 
[void]
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

 

 
## Create and build the form from the function ##

 
    $Form
=
New-Object
system.Windows.Forms.Form
        $Form.Text =
"VSC Rename & Domain Join"
        $Icon
=
[system.drawing.icon]::ExtractAssociatedIcon($PSHOME
+
"\powershell.exe")

        $Form.Icon = $Icon
        $Form.AutoScroll = $True
        $Form.AutoSize = $True
        $Form.AutoSizeMode =
"GrowAndShrink"
# or GrowOnly
        $Form.MinimizeBox = $False
        $Form.MaximizeBox = $False
        $Form.WindowState =
"Normal"
# Maximized, Minimized, Normal
        $Form.SizeGripStyle =
"Hide"
# Auto, Hide, Show
        $Form.ShowInTaskbar = $False
        $Form.Opacity =
1.0
# 1.0 is fully opaque; 0.0 is invisible
        $Form.StartPosition =
"CenterScreen"
# CenterScreen, Manual, WindowsDefaultLocation, WindowsDefaultBounds, CenterParent
        $Font
=
New-Object
System.Drawing.Font("Times New Roman",12,[System.Drawing.FontStyle]::Bold) # Font styles are: Regular, Bold, Italic, Underline, Strikeout
        $Form.Font = $Font

 
    $Label
=
New-Object
System.Windows.Forms.Label
        $Label.Text =
"Enter base Computer Name (i.e., PCX-IT-):"
        $Label.AutoSize = $True
        $Form.Controls.Add($Label)

 
    $Textbox
=
New-Object
System.Windows.Forms.TextBox
        $Textbox.Location =
New-Object
System.Drawing.Size(10,50)
        $Textbox.Size =
New-Object
System.Drawing.Size(260,300)
        $Form.Controls.Add($Textbox)
    
    $Label2
=
New-Object
System.Windows.Forms.Label
        $Label2.Text =
"Enter base Computer Number(i.e., 100):"
        $label2.Location =
New-Object
System.Drawing.Size(10,100)
        $Label2.AutoSize = $True
        $Form.Controls.Add($Label2)

 
    $Textbox2
=
New-Object
System.Windows.Forms.TextBox
        $Textbox2.Location =
New-Object
System.Drawing.Size(10,150)
        $Textbox2.Size =
New-Object
System.Drawing.Size(40,60)
        $Form.Controls.Add($Textbox2)

 
    $Label3
=
New-Object
System.Windows.Forms.Label
        $Label3.Text =
"Enter number of computers created (i.e., 100):"
        $label3.Location =
New-Object
System.Drawing.Size(10,200)
        $Label3.AutoSize = $True
        $Form.Controls.Add($Label3)

 
    $Textbox3
=
New-Object
System.Windows.Forms.TextBox
        $Textbox3.Location =
New-Object
System.Drawing.Size(10,250)
        $Textbox3.Size =
New-Object
System.Drawing.Size(40,60)
        $Form.Controls.Add($Textbox3)

 
    $Label4
=
New-Object
System.Windows.Forms.Label
        $Label4.Text =
"Enter Domain Name (i.e., contoso.com):"
        $label4.Location =
New-Object
System.Drawing.Size(10,300)
        $Label4.AutoSize = $True
        $Form.Controls.Add($Label4)

 
    $Textbox4
=
New-Object
System.Windows.Forms.TextBox
        $Textbox4.Location =
New-Object
System.Drawing.Size(10,350)
        $Textbox4.Size =
New-Object
System.Drawing.Size(260,300)
    $Textbox4.Text =
"na.erac.com"
        $Form.Controls.Add($Textbox4)

 
    $Label5
=
New-Object
System.Windows.Forms.Label
        $Label5.Text =
"Select the target OU:"
        $label5.Location =
New-Object
System.Drawing.Size(10,400)
        $Label5.AutoSize = $True
        $Form.Controls.Add($Label5)

 

[array]$OUs =
"Windows 7 Admin OU - CORP Domain",

"Windows 7 OU - CORP Domain"

 

$Combobox
=
New-Object
System.Windows.Forms.ComboBox

$Combobox.Location =
New-Object
System.Drawing.Size(10,450)

$Combobox.Size =
New-object
System.Drawing.Size (500,300)

Foreach ($Item
in
$OUs){

$Combobox.Items.Add($Item)
}

$Form.Controls.Add($Combobox)

 
    $Label6
=
New-Object
System.Windows.Forms.Label
        $Label6.Text =
"Enter XenServer Host or Pool Master:"
        $label6.Location =
New-Object
System.Drawing.Size(10,500)
        $Label6.AutoSize = $True
        $Form.Controls.Add($Label6)

 
    $Textbox6
=
New-Object
System.Windows.Forms.TextBox
        $Textbox6.Location =
New-Object
System.Drawing.Size(10,550)
        $Textbox6.Size =
New-Object
System.Drawing.Size(260,300)
        $Form.Controls.Add($Textbox6)

 
    $Label7
=
New-Object
System.Windows.Forms.Label
        $Label7.Text =
"Enter XenServer Username:"
        $label7.Location =
New-Object
System.Drawing.Size(10,600)
        $Label7.AutoSize = $True
        $Form.Controls.Add($Label7)

 
    $Textbox7
=
New-Object
System.Windows.Forms.TextBox
        $Textbox7.Location =
New-Object
System.Drawing.Size(10,650)
        $Textbox7.Size =
New-Object
System.Drawing.Size(260,300)
        $Form.Controls.Add($Textbox7)

 
    $Label8
=
New-Object
System.Windows.Forms.Label
        $Label8.Text =
"Enter XenServer Password:"
        $label8.Location =
New-Object
System.Drawing.Size(10,700)
        $Label8.AutoSize = $True
        $Form.Controls.Add($Label8)

 
    $Textbox8
=
New-Object
System.Windows.Forms.TextBox
        $Textbox8.Location =
New-Object
System.Drawing.Size(10,750)
        $Textbox8.Size =
New-Object
System.Drawing.Size(260,300)

$Textbox8.PasswordChar =
'*'
        $Form.Controls.Add($Textbox8)

 
    $OKButton
=
New-Object
System.Windows.Forms.Button
        $OKButton.Location =
New-Object
System.Drawing.Size(100,800)
        $OKButton.Size =
New-Object
System.Drawing.Size(90,60)
        $Font1
=
New-Object
System.Drawing.Font("Times New Roman",10,[System.Drawing.FontStyle]::Regular) # Font styles are: Regular, Bold, Italic, Underline, Strikeout
        $OKButton.Font = $Font1
        $OKButton.Text =
"OK"
        $OKButton.Add_Click({$x=$TextBox.Text;$Form.Close()})

 

$Form.Controls.Add($OKButton)

$Form.ShowDialog()

 
###Build Computer Name Varibles ###
$BaseCompName
=
$Textbox.Text
$BaseCompNum
=
$Textbox2.Text
[String]$ComputerName =
[string]$BaseCompName +
[string]$BaseCompNum
$NumComputers
=
$Textbox3.Text
[Decimal]$b =
[Decimal]$BaseCompNum +
[Decimal]$NumComputers

 
### Varibles to join PC to domain ###
$Credential
=
Get-Credential
-Message
"Enter Domain Account"
-UserName
"CORP\USER"
$Domain
=
$Textbox4.Text

 
### XenServer Varibles ###
$XenHost
=
$Textbox6.Text
$XenUser
=
$Textbox7.Text
$XenPwd
=
$Textbox8.Text

 
### Translate OU selection to actual OU distinguishedName ###
$OUPath
=
$Combobox.SelectedItem.ToString()

 

If ($OUPath
-eq
"Windows 7 Admin OU - NA Domain"){

$OUPath
=
"OU=Win 7 Dedicated Admin,OU=Virtual Desktops,OU=Workstations,DC=CORP,DC=COM"
}

If ($OUPath
-eq
"Windows 7 OU - NA Domain"){

$OUPath
=
"OU=Win 7 Dedicated,OU=Virtual Desktops,OU=Workstations,DC=CORP,DC=COM"
}

 
### Check for Comps.CSV, if it exists remove it! ###
$CSV
=
Test-Path
C:\Test\Comps.CSV

 
if ($CSV
-eq
"True") {
    Remove-Item
C:\Test\Comps.CSV
}

 
$Column
=
"Name,IP"
Add-Content
C:\Test\Comps.CSV
$Column

 
#Import-Module "C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\psModules\virtualmachinemanager\virtualmachinemanager"

 
Add-PSSnapin
XenServerPSSnapIn
Connect-XenServer
-Server
$XenHost
-UserName
$XenUser
-Password
$XenPwd

 
### Loop through each computer name and get its IP address. Add the name and IP to the CSV ###
Do {$vm
=
Get-XenServer:VM
-Server
$XenHost
-NameFilter
$ComputerName
    ;$arr
=
Get-XenServer:VM_guest_metrics.Networks
-VMGuestMetrics
$vm.guest_metrics
    ;$IP
=
$arr["0/ip"]
    ;$AddComp
=
$ComputerName
+
","
+
$IP
    ;Add-Content
C:\Test\Comps.CSV
$AddComp

 
    ;[Decimal]$NewCompNum =
[Decimal]$BaseCompNum +
1
    ;[String]$BaseCompNum =
[String]$NewCompNum
    ;$ComputerName
=
$BaseCompName
+
$BaseCompNum
}
Until ($NewCompNum
-eq
$b)

 
### read from CSV and list comps ####
$VMComps
=
Import-CSV
C:\Test\Comps.CSV
$LocalCred
=
Get-Credential
-Message
"Enter the Local Admin Account"
-UserName
"ADMINISTRATOR"

 
### Rename/restart each VM ###
Foreach ($VMComp
in
$VMComps) {

Rename-Computer
-ComputerName
$VMComp.IP -NewName $VMComp.Name -Force
-LocalCredential $LocalCred


Add-Computer
-ComputerName
$VMComp.Name -Credential $Credential
-DomainName
$Domain
-OUPath
$OUPath
-LocalCredential
$LocalCred
-Restart
-Options
JoinWithNewName
}

 

 
### Build XD Catalog Import CSV ###
Write-Host
"Building XenDesktop Import CSV"
$XDCsvHeader
=
"[VirtualMachinePath],[ADComputerAccount],[AssignedUsers]"
$XDConnectBase
=
"XDHyp:\connections\PVS Task Pool\"

 
$XDCSV
=
Test-Path
C:\Test\Import.CSV

 
if ($XDCSV
-eq
"True") {
    Remove-Item
C:\Test\Import.CSV
}

 
Add-Content
C:\Test\Import.CSV
$XDCsvHeader

 
Foreach($VMComp
in
$VMComps){

$XDCsvLine
=
$XDConnectBase
+
$VMComp
+
".vm,NA\"
+
$VMComp
+
"$"

Add-Content
C:\Test\Import.CSV
$XDCsvLine
}
Write-Host
"XenDesktop Import CSV Complete."
Write-Host
"The file, IMPORT.CSV, is located on C:\TEST\"

 

 
### Remove host affinity so it'll failover properly! ###
Foreach ($VMComp
in
$VMComps){

Set-XenServer:VM.Affinity
-VM
$VMComp
-Server
$NULL
}

 
####### Done! #####
Write-Host
"Completed"



More information on PowerShell


Read more!

Sunday, July 25, 2010

IPad works as a Systems Administrator Tool

By: David Merrell
Last couple weeks I have been traveling back and forth to a client. During my trips I sat in the airport for several hours being bored and really did not want to break out the big 17 inch, 5 Pound laptop to get ahead of some work for a project I was working on. So I was needing something to help to accomplish this while waiting for my plane. The project I was working on was a XenDesktop, XenApp POC for a university in north Texas. My boss has an IPAD and was showing off the Citrix Receiver and Citrix Dazzle a few weeks earlier. I started thinking it would be nice to have a light weight easy to use tool to help me instead of the laptop. Next trip to Texas I picked up a 64 Gb IPAD. The sales guy was asking what I was going to use it for, I told him business mainly and of course he tried to sell me the 3G version. I figured I have an awesome HTC Touch Pro 2, Windows Mobile phone which acts as a wireless access point, so didn't need the 3G charge. Here is the scenario that I used the IPad as an administrator tool: I was able to remote into all the infrastructure servers using for the environment finish configuration using Desktop Connect. I was able to use the Citrix Receiver to connect to a published Citrix XenCenter to administer the XenServers. The Citrix Receiver also allowed me to test the published XenApp applications and desktops; it also allowed me to test the XenDestops. The IPad and the listed apps below is a great set of tools to allow me to provide better support to our customers and be more efficient on the projects I work on.


Here is a list of the apps and descriptions, I installed and use just for the purposes:

APP

Review

Desktop Connect

Desktop Connect is a fast, full-featured desktop viewer, optimized specifically for the IPad. View and control Windows, Mac OSX and Linux computers as if you were sitting in front of them, or observe others as if you were watching over their shoulder.

Desktop Connect is one of the best remote applications I have installed. As a systems administrator the RDP connection was easy to configure and use. The speed of the app is very efficient.

LogMeIn Ignition

One click on your iPad lets you remotely access one or more computers anywhere, anytime.

LogMeIn is a client based app that allows access to systems that may not have the ability to RDP or restricted by firewalls, I mainly use this app for my home network. This app provides another layer of security, it also was easy to setup and configure.

Citrix Receiver

Citrix Receiver for IPad is the perfect business solution for secure access to virtual desktops, applications and data.

As a Systems Engineer that works with XenDesktop, XenApp and XenServer setting up an administration group of apps and XenDesktop to support an environment the Citrix Receiver makes it easier to connect to tools such as the Citrix admin consoles.

Vtrace

Vtrace is a visual traceroute application that shows a list of the networks serves from your machine to a target ip address or hostname on a google map.

This application is a great visual traceroute program, it works well as a network troubleshooting app.

DNS Lookup Tool

DNS lookup tool to find A records, MX records, Name Servers and reverse DNS records for IP addresses and domains.

The description pretty much says it all. At the time of writing this article, this is only an IPhone up but works well with the IPad.

FreePing

FreePing is an ICMP Ping Application. It is designed to have a simple and intuitive user experience.

Again pretty much works as the description says, it also is only for the IPhone at the time of the writing.

Mocha Telnet Lite

Mocha Telnet provides access to servers via Telnet

This is a good tool to telnet to ports on servers to make sure all the necessary ports are accessible.

iXen

This App helps you administrate common tasks on virtual machines running on a Citrix XenServer.

The main functions of this app allow you to Boot, Shutdown, Suspend, Rest and Turn off virtual machines. This is a handy tool if you do not have access to the XenServer console.



Read more!

Friday, April 23, 2010

XenServer 5.6 Preview, Part 1: Dynamic Memory Control

By:Andy Paul

I've had the opportunity to work with the XenServer 5.6 Beta and wanted to share a few of the new and improved features. With this latest release, Citrix XenServer is getting closer to the functionality of VMWare. I'm seeing more implementations of XenServer as it matures. Most of these implementations generally for new customers who do not have a virtualization initiatives or customers who are "Citrix shops." However, I do see more and more VMWare customers I work with who are adopting XenServer in parallel to their existing infrastructure.

There is no denying that vSphere is the more mature and more robust product. Just like there is no denying that it is more expensive and can be more complex. I generally say that XenServer will get you 90% of the way there at a much lower price tag, and for most customers that is plenty. With these new updates, that margin of difference is decreasing.

XenServer 5.6 Beta includes a number of new features and ongoing improvements. The full list can be seen here, but today, I want to focus on Dynamic Memory Control. This is the feature that peaks the most interest of administrators.

Personally, I have never been a fan of over-allocating memory. Virtualization allows dynamic use of resources, but those resources are not limitless. However, there are times when you need to use overallocation, such as lab, PoC, and Test/Dev environments. Using the DMC in XenServer 5.6 through the XenCenter console is easy and intuitive. As you can see in the picture below, you can monitor the "big picture" of the host, as well as the individual impact on each VM -- so you really know how and where your memory is being used.  The first image below show the memory allocation without DMC configured (the host only has 4 GB of RAM); the second image shows the memory allocations after adjusting the memory ranges (the host is now over committed -118%)

 Note, the VMs are running in a variety of memory configurations:
  • XDPOCDDC VM is configured to run between 1024 and 2048 MB, the Guest OS (Win 2003) see 2048 available RAM
  • XDPOCWINXP1 was configured at 512 static, I modified it to range between 512 and 768.  Because it was not using DMC before this change, a reboot is required to complete the RAM increase
  • XDPOCWINXP2 was configured at 1024 static, I modified it to range between 768 and 1024.
  • XDPOCWINXP3 is still configured for 512 static (min and max are the same value)

Per Citrix -- "Dynamic Memory Control. This feature can increase the number of VMs per host by permitting the memory utilization of existing VMs to be compressed so that additional VMs can boot on the host. Once VMs on that host are later shut down or migrated to other hosts, running VMs can reclaim unused physical host memory. Dynamic Memory Control is enabled by defining minimum and maximum memory settings for virtual machines."

Basically, this is the over-commit VMWare has been long known for. Dynamic Memory Control (DMC) provides the following benefits:
  • Memory can be added or removed without restarting the VM,  providing a seamless experience to the user.
  • When host servers are full, DMC allows you to start more VMs on these servers, reducing the amount of memory allocated to the running VMs proportionally.
  • As memory requirements on the host change, DMC will auto-adjust the memory of running VMs, but will keep the memory within a range specified by the administrator.
For each VM the administrator can set a dynamic memory range - this is the range within which memory can be added/removed from the VM without requiring a reboot. When a VM is running the administrator can adjust the dynamic range. XenServer always guarantees to keep the amount of memory allocated to the VM within the dynamic range; therefore adjusting it while the VM is running may cause XenServer to adjust the amount of memory allocated to the VM. 
DMC allows you to configure dynamic minimum and maximum memory levels – creating a Dynamic Memory Range (DMR) that the VM will operate in. In XenCenter, this can be configure to a fixed memory, or a range.  The range can be defined manually or using the graphical tool to slide the setting points. This is analogous to Memory Reservations in VMWare.

DMC Behavior: Automatic VM squeezing
If a new VM is started on a XenServer with "full" memory already assigned the running VMs have their memory 'squeezed' to start new ones. The required extra memory is obtained by reducing the existing running VMs proportionally within their pre-defined dynamic ranges. Of course, if a VM is set to Fixed Memory and the Host is "full," the an "out of memory" failure will occur.

When DMC is enabled, and the host's memory is plentiful, then all running VMs will receive their Dynamic Maximum Memory level. When a host's memory is scarce, all running VMs will receive their Dynamic Minimum Memory level (or close too it). Again, the memory sharing is proportional.

Please note, the Dynamic Memory Control requires a Citrix Essentials for XenServer license. As of XenServer 5.6, this is centrally managed via the Citrix License Management Console. You can download XenServer 5.6 Beta as well as the require Essentials License files here (MyCitrix Login is Required).
Next Installment: Role Based Security and XenCenter Changes

Read more about XenServer


Read more!
Microsoft Virtualization, Citrix, XENServer, Storage, iscsi, Exchange, Virtual Desktops, XENDesktop, APPSense, Netscaler, Virtual Storage, VM, Unified Comminications, Cisco, Server Virtualization, Thin client, Server Based Computing, SBC, Application Delivery controllers, System Center, SCCM, SCVMM, SCOM, VMware, VSphere, Virtual Storage, Cloud Computing, Provisioning Server, Hypervisor, Client Hypervisor.