Powershell: Set Logon Hours for all the users in an OU


image

With the script in this post you’re able to set logon hours to a bunch of users. All you have to do is to setup logon hours for a “template” user and define this “template” user into the $template variable.

image

The other step is to define the $ou variable with the path to the OU. In my case this was ict-freak/Gebruikers.

The script will now read the default logon hours and will apply them to the users in the OU.

$template = "" # This is a user with the default logon hours
$ou = "" # the full path to your ou "domainname/ouname1/ouname2"

# Get the logonhours from the template user
$template = Get-QADUser $template -IncludedProperties logonhours
[array]$logonHours = $template.DirectoryEntry.logonHours

# Get all users
$users = Get-QADUser -OrganizationalUnit $ou

# Loop through all the users
foreach($user in $users){
    Set-QADUser $user.Name -oa @{logonHours = $logonHours}
}

 

I found this trick here: http://www.powergui.org/thread.jspa?threadID=7860

Release: Veeam Backup 3.1.1.295


image

@Gostev has published the news on Twitter:

image

The Release Notes:

New Features
• Added support for replication and remote backup over slow and unreliable links with moderate packet loss.
Resolved Issues
• .NET Framework bug affecting some non-English locales (confirmed to exist on Norwegian locale) results in sporadic corruption of backup files chain (missing VBK files, extra VRB files).
• Backup file repair after unsuccessful backup cycle fails if backup storage is low on free disk space.
• Network backup in service console agent mode may fail with the following error: “Failed to validate command "dd if="/vmfs/volumes/…”.
• Attempting to enable SSH connection to ESX host on Japanese locale fails with the following error: ["Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "VeeamSSH.strings.ja.resources" was correctly embedded or linked into assembly "Veeam.SSH" at compile time, or that all the satellite assemblies required are loadable and fully signed."].
• Veeam VSS processing fails on specific OS configurations with various “Access denied” errors while specified VSS account has suffient permissions.
• Veeam VSS processing fails on specific OS configurations with the following error: "The specified service does not exist as an installed service".
• Veeam VSS integration does not support guests with Datacenter Edition of Microsoft Windows 2003.

You can download the new release here: http://www.veeam.com/vmware-esx-backup/download.html

Source: http://www.veeam.com/forums/viewtopic.php?f=2&t=1565

vSphere: Deploy Template grayed out


image

I wanted to deploy a template via the vSphere client but I was unable to achieve this task because the option was grayed out.  After restarting the vCenter services and the vCenter server I was still unable to deploy a template.

image

Non of the options where available. So PowerCLI to the rescue:

$templates = Get-Template *
    foreach($item in $templates){
        $template = $item.Name
                
            #Convert Template back to VM
            Set-Template $template -ToVM -RunAsync
            #Convert Template back to template :S
            $vmview = Get-VM $template | Get-View
            $vmview.MarkAsTemplate()
            
    }

 

After running the script above. I was able to deploy my templates again 🙂

image

VMware: Failed to get disk partition information in vSphere


image

Today I wanted to add a new iSCSI Lun to my vSphere Lab. I got the following error:

image

I had this error in the past, see my previous post: vmware-failed-to-get-disk-partition-information. I tried the solution described in my previous post but it didn’t  work in vSphere.

So I had to search for another solution. Luckily VMware released a KB document. See KB1008886. In this KB document VMware uses the command esxcfg-vmhbadevs. This command is replaced with a new command called esxcfg-scsidevs.

So I ran the esxcfg-scsidevs command on the service console:

image

After running the command, write down the following line: Console Device: /dev/sdc. Start Parted and walk through the following steps.

Note: don’t forget to change the /dev/sdb to the device you need to fix. In my case /dev/sdc.

To change the label and partitioning scheme:

Caution: This removes the pre-existing partition table, and any data on the volume is no longer be available. Ensure you are operating against the correct disk.

  1. Start parted to analyze the existing partition. Print the existing partition information, taking note of the Partition Table, size, and name. Ensure this is the data intended to be removed.
    Run the following commands:
    [root@esx ~]# parted /dev/sdb
    GNU Parted 1.8.1
    Using /dev/sdb
    Welcome to GNU Parted! Type ‘help’ to view a list of commands.
    (parted) print
    Disk geometry for /dev/sdb: 0.000-512.000 megabytes
    Disk label type: gpt
    Number  Start   End    Size   File system  Name                          Flags 
    1      17.4kB  134MB  134MB               Microsoft reserved partition  msftres
  2. Change the partition table (disklabel) type to msdos. This deletes the pre-existing partitions. Print the partition table again to observe the changes. Quit parted.
    Run the following commands:
    (parted) mklabel msdos
    (parted) print
    Disk geometry for /dev/sdb: 0.000-512.000 megabytes
    Disk label type: msdos
    Minor    Start       End     Type      Filesystem  Flags
    (parted) quit
  3. Return to the VI Client and use the Add Storage wizard again. Choose the same LUN, create a new partition, and format it with a VMFS Datastore as normal.

Source: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1008886

PowerCLI: Fast vMotion script with GUI


image

Gabrie dropped the following message on Twitter:

@gabvirtualworld *sigh* Why do I always have to reselect the resource pool when migrating VMs? Now I can’t move multiple VMs at once when in diff pools.

Well I felt the same about this. For the people who don’t know what Gabrie means whit his tweet, I will add two screenshots to explain it. When you start the Migrate (VMotion) task, You need to select what kind of migration you want to do. I choose the Change host option:

image

If you want to migrate multiple VM’s then I think you will find the next screen as annoying as I and Gabrie find it.

image

So to get rid of this annoying option. I created a script with an UI to VMotion multiple VM’s at the same time. Note: You can only VMotion  to one Selected host.

This is a printscreen of the GUI of the script:

image

I created a movie of the script in action:

You can download the script here: http://poshcode.org/1220

Gabrie thanks for testing the script!

PowerCLI: Find and Set the Service Console Memory value


image

Last year I wrote a blog post about changing the COS memory. You can find the post here: https://ict-freak.nl/2008/11/26/vmware-service-console-memory/ (it’s written in Dutch). In that post there is already a one-liner made by LucD butt in this post you’ll get an extra one-liner to determine the COS memory value.

If you want to see how much memory is allocated for the Service Console run the next script:

Get-VMHost | Sort Name | Get-View | Select Name, `
@{N="Service Console Memory";E= {"" + `
[math]::round($_.Config.ConsoleReservation.ServiceConsoleReserved / 1MB, 0) + " MB "}}

 

Just add | Export-Csv -NoTypeInformation "D:\cosmem.csv" to export the data to a CSV file.

The output will look like this:

image

The script/one-liner:

Get-VMHost | Get-View | % { 
$_.Name | Where { $_.Config.ConsoleReservation.ServiceConsoleReserved -eq "314572800" }
(Get-View -Id $_.ConfigManager.MemoryManager).ReconfigureServiceConsoleReservation(800*1mb) }
 

You can monitor the changes in vCenter:

image 

More information about the maximum values can be found here:  vsp_40_config_max.pdf.

The maximum value for the COS Memory is 800MB so that’s what the script will use to set the COS memory.

Note: You have to restart the server to apply the changes.

Xtravirt: VMware Documentation Downloader


image

Paul Buckle van www.xtravirt.com has released an awesome script called VMware Documentation Downloader. 

Requirements

  • Microsoft Windows
  • GetVMwareDocs.bat script (download latest version below)
  • wget.exe utility (wiki available here and download utility at http://users.ugent.be/~bpuype/wget)
  • Minimum of 650MB free disk space (this requirement will increase over time as VMware publish new documentation)
  • Internet access (direct, or via an HTTP proxy)
  • .txt files have been associated with a document viewer
  • .html files have been associated with a web browser

Installation

  • Create a folder to contain the script and the downloaded files (eg. C:\VMwarePDFs).
  • Download GetVMwareDocs.bat and wget.exe and save them to this folder.

Alternatively, copy an existing “installation” from another machine.

So if you want an offline copy of the VMware documents, grab a copy of the script here: http://xtravirt.com/xd10109 (you have to sign in). Download wget,exe and you’re ready to download the docs.

The script in action:

image

PowerCLI: Upgrading vHardware to vSphere Part 2: VM’s


image

Disclaimer: use this script at your own risk 😉

In part 1 you could find a script to upgrade your templates to hardware version 7. In this post you’ll find a script that will upgrade your VM’s to hardware version 7.

Note: This script will upgrade the VMware Tools if necessary and will shutdown the VM!!!!!

You can download the script here: upgrade-vhardware_vm and here: http://poshcode.org/1217

The script will perform the following actions:

  • Connect to vCenter
  • Get all the VM’s in the folder you need to specify
  • Create a CSV file with some info about the VM. I will post the content later.
  • Update the VMware Tools if necessary (The VM will restart after the installation)
  • Shutdown the VM
  • Upgrade the vHardware to version 7
  • Start the VM
  • Create an Excel sheet with an overview of the VM’s and their IP settings

During the process of the script, the VM will be unavailable for 5 minutes or less. So be sure that nobody uses the VM.

The beforeHWchange.csv will look like this:

image

The script in action:

image

The last step, the creation of an Excel sheet with an overview of the VM’s. Here you can see if the IP Address is changed or not.

image

To do list:

  • Create a proper VM report function (export to csv) so I can capture multiple network adapters.
  • Create a before Excel sheet with a nice overview of the environment.

vSphere: Rescan for Datastores


image

Today I added a second Lun on my iSCSI box. The next step was to configure this Lun on one of my vSphere boxes. So I did a rescan on vmhba34 and formatted it to VMFS. The next step, which I think is an excellent new feature in vSphere, was a “Rescan for Datastores”:

image

I started the wizard on a Cluster and it will only ask you to set two options:

image

So I checked both the options and did a Rescan. After a couple of seconds my other host was configured and showed the new Lun.