Report Guest Disk Sizes | PowerCLI

I already explained in my previous post how to grow/extend Guest OS disks with PowerCLI.

Now before we can increase harddrives we also need to identify them. I therefor created this script.

$MyCollection = @()
$AllVMs = Import-Csv -Header Desktop "hdd-check-input.csv" | foreach-object { Get-View -ViewType VirtualMachine -Filter @{"Name" = $_.Desktop}}
$SortedVMs = $AllVMs | Select *, @{N="NumDisks";E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
ForEach ($VM in $SortedVMs){
 $Details = New-object PSObject
 $Details | Add-Member -Name Name -Value $VM.name -Membertype NoteProperty
 $DiskNum = 0
 Foreach ($disk in $VM.Guest.Disk){
 $Details | Add-Member -Name "Disk$($DiskNum)path" -MemberType NoteProperty -Value $Disk.DiskPath
 $Details | Add-Member -Name "Disk$($DiskNum)Capacity(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.Capacity/ 1MB))
 $Details | Add-Member -Name "Disk$($DiskNum)FreeSpace(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1MB))
 $DiskNum++
 }
 $MyCollection += $Details
}
$MyCollection | export-csv hdd-check-output.csv
#Out-GridView
# Export-Csv, ConvertTo-Html or ConvertTo-Xml can be used above instead of Out-Gridview

The advantage using get-view is the nice performance if you run this script.

Try it out. You cant break things 🙂 It will give you a nice .csv as output.

View | Unassign User PowerCLI

If you dont want to unassign all users by hand simply provide this script a .csv file with desktop names and it will do it for you.

$filepath = "desktops.csv"
import-csv $filepath -Header Desktop | Foreach-object {
remove-userownership -machine_id (Get-DesktopVM -name $_.Desktop).machine_id
} 

 

Change & Grow VM Hard Disk

We are right now in the need of resizing all of our Hard Disks on the Virtual Desktop VMs from 40GB to 60GB.
I was looking quite some time to find the appropriate command and this is how you do it:

Get-HardDisk -vm "VMName" | where {$_.Name -eq "Hard Disk 1"} | Set-HardDisk –CapacityKB 62914560 -ResizeGuestPartition -Confirm:$false

A little bit of extra information (we ran into some issues performing this):

The second part of the script (Set-Harddisk) actually calls a library function that is using the “Invoke-VMScript” command.

You need to have following privileges on the vCenter System to execute it.
VirtualMachine.GuestOperations.Modify and VirtualMachine.GuestOperations.Execute.

vmware

Update:

This script makes it even more comfortable. You provide a list of desktops in the input file and it will do all of them in one run. After that you will see a report of the changes in the output file.

Import-Csv -Header Desktop "hdd-increase-input.csv" | foreach-object { Get-HardDisk -vm $_.Desktop | where {$_.Name -eq "Hard disk 1"} | Set-HardDisk –CapacityKB 62914560 -ResizeGuestPartition -Confirm:$false
Write-host "-----------------------------------------------------------------------------------------" -foregroundColor White -backgroundColor DarkGreen
} | export-csv "hdd-increase-output.csv"

New Job

Since the 1st of july i finally got into a very interesting position in my company.
I will now be responsible for support, reporting and analysis of a VMWare View virtual desktop infrastructure.
Starting off with a 90day training plan and a View 5.2 class room training i am looking forward to be on a good level pretty soon.

Apache 2 & SSL

Just activated SSL on my apache2 VirtualHost for this page.
Pretty straight forward. Just “a2enmod ssl” to get ssl activated.
After that i’ve chosen to enable SSL specifically in my beutler.nl virtualhost.

Configuration looks like this now:

<VirtualHost *>
....
SSLEngine on
SSLCertificateFile /dir/to/.cert
SSLCertificateKeyFile /dir/to/privatekey
NameVirtualHost *:443
Listen 80
Listen 443

Make sure in your ports.conf is also mentioned: NameVirtualHost *:80

In case of questions – let me know 🙂

Roundcubemail

Just added roundcubemail to my dovecot imap server.
It's a nice and clean Dovecot Webfrontend (or imap webfrontend).

Pretty straight forward install.

http://roundcube.net/

First i tried to use the apt-get install roundcube function but it ended up in installing like 25 packages i didn't need in the end. I can really recommend going the manual procedure and downloading the rc1.0 version. Very clean UI and just works 🙂

Dovecot & imap

Just wanted to install dovecot-imapd when i noticed my dovecot-core installation was somehow corrupt. Got error message like these from top to bottom:

dpkg: error processing dovecot-core (--configure): subprocess installed post-installation script returned error exit status 1 dpkg: dependency problems prevent configuration of dovecot-common: dovecot-common depends on dovecot-core; however: Package dovecot-core is not configured yet. dpkg: error processing dovecot-common (--configure): dependency problems - leaving unconfigured Errors were encountered while processing: dovecot-core dovecot-common

When checking /var/log/syslog i noticed this error message:

Mar 24 20:50:22 h2077265 dovecot: master: Fatal: service(pop3) access(/usr/lib/dovecot/pop3) failed: No such file or directory

And guess what – i just had to make the directory and after that i was able to apt-get purge. Everything has been reinstalled again. Now i was also able to apt-get install dovecot-imapd. After enabling imap in /etc/dovecot/dovecot.conf (protocols = imap pop3) and a restart of dovecot everything was working.

Another one done. Now lets go for webmail 😉

[Apache] Name based virtual host

So after quite some time now i became annoyed of my FQDN and wanted something easier to read/share. I’ve bought a domain from godaddy.com (anyone knows something better?) and wanted to add it to my existing webhost. After setting the A-record to my static server IP it took only about 10 minutes to get the change live. Now as my root server (debian v7.x) only got one IP and already some other sites on it i had to use Apache name based virtual hosts. I never really used it in the past. Other domains i am hosting are just pointed to my old FQDN and the folder where the sites are stored in. PRETTY LAME!

Now virtual hosts are a lot easier to use then i expected. I just added a new file into the directory /etc/apache2/sites-enabled. You can use the default web page as pretty good example.

Notice that most pages advice you to start with NameVirtualHost *:80 to enable name based virtual hosts. You only need this if it’s not included before already! In my example my apache2.22 already had this activated when including the ports.conf configuration file. After that i went straight forward and added this configuration into my newly created file (in sites-enabled):

<VirtualHost *:80>
ServerAdmin a@bc.de
ServerName www.beutler.nl
ServerAlias beutler.nl *.beutler.nl

DocumentRoot /directory/beutler.nl
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /directory/beutler.nl>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/beutler.nl.error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/beutler.nl.access.log combined
</VirtualHost>

Now i restarted apache and it just worked. That easy 🙂 Of course i also moved all other pages i host to virtual hosts and changed URL forwarding (from the domain provider) to a new A-record. Looks a lot more professional now.

So what – i am still learning 🙂 If you got any questions just let me know.

New Blog

Hi all,

i decided to finally get a blog running (yeah i know it’s 2014).
Basically this blog is about my day to day experience with IT stuff.
At the moment it’s pretty much only web/server hosting and playing around with my raspberry pi. I feel like a lot of the information in the internet is outdated and most of the times blogs (can) contain a lot of useful tips and tricks. So hopefully this will be one more of those neat sites.

Enjoy your week.

best, Niko