How to manage iSCSI targets with PowerCLI part 2


In part 2 of this series I will show how to remove iSCSI targets with PowerCLI.

But first, let’s see which targets are configured on vSphere host esx2.ict-freak.local:

$esx = Get-VMHost "esx2.ict-freak.local"
Get-IScsiHbaTarget -IScsiHba ($esx | Get-VMHostHba -Type iScsi | Where {$_.Model -eq "iSCSI Software Adapter"})

The following targets are configured:

image

In this post I want to show you how to remove the target with PowerCLI. So I opened the vSphere PowerCLI Cmdlets Reference and searched for the Remove-IScsiHbaTarget. On this page you’ll find the following examples:

————– Example 1 ————–

Get-IScsiHbaTarget -Address 10.23.84.73 -Type Send | Remove-IScsiHbaTarget

Retrieves and removes the targets of type Send on the specified address.

————– Example 2 ————–

Remove-IScsiHbaTarget -Target (Get-IScsiHbaTarget -Address 10.23.84.73)

Removes the specified iSCSI HBA targets.

Unfortunately this example doesn’t work because the –Address parameter doesn’t exist in VMware vSphere PowerCLI 4.1 build 264274.

Continue reading “How to manage iSCSI targets with PowerCLI part 2”

How to manage iSCSI targets with PowerCLI part 1


In part 1 of this series I want to show some basic reporting and how you can add a single target and multiple targets to your vSphere hosts. Let’s start with a simple script to report all the targets on all your vSphere hosts:

$esxHosts = Get-VMhost
foreach($esx in $esxhosts){
$hba = $esx | Get-VMHostHba -Type iScsi 
    Write-Host "=========================================="
    Write-Host "iSCSI Targets on $esx"
    Write-Host "=========================================="
    Get-IScsiHbaTarget -IScsiHba $hba -Type Send | Sort Address
    Write-Host " "
}

The following output will be generated:

image

Continue reading “How to manage iSCSI targets with PowerCLI part 1”

PowerCLI: Enable Beacon Probing or Link Status Only on a vSwitch


In some cases you need to troubleshoot your network infrastructure from your vSphere hosts all the way back into your core network. In this case you can enable beacon probing and watch your log files for issues. But before I continue to show how to enable beacon probing I want to share some information about what beacon probing is and when is it recommended to be used :

Beacon Probing is a network failover detection mechanism that sends out and listens for beacon probes on all NICs in the team and uses this information, in addition to link status, to determine link failure.

This detects failures, such as cable pulls and physical switch power failures, but not configuration errors, such as a physical switch port being blocked by spanning tree or misconfigured to the wrong VLAN or cable pulls on the other side of a physical switch that are not detected by link status alone.
Beacon probing is most useful to detect failures in the closest switch to the ESX hosts, where the failure does not cause a link-down event for the host.

You can use beaconing with 2 NICs, but this only detects failures on the immediate uplink. If you really want to detect upstream failures, use beaconing with 3 or more NICs.
When there are only two NICs in service and one of them loses connectivity it is unclear which NIC needs to be taken out of service as both no longer receive beacons. Using at least 3 NICs in such a team allows for N – 2 failures where N is the number of NICs in the team before getting into an ambiguous situation.

Source:KB1005577

More information about beacon probing can be found here: http://blogs.vmware.com/networking/ and in part 4 of the great vSwitch debate: http://kensvirtualreality.wordpress.com/2009/04/10/the-great-vswitch-debate-part-4/

Continue reading “PowerCLI: Enable Beacon Probing or Link Status Only on a vSwitch”

How To: Configure vSphere 4.1 Active Directory Authentication


In this post I will show you how to setup Active Directory Authentication in vSphere 4.1.

What do we need tot do:

– Before you start. Please make sure that DNS and NTP are fully functional.
– Create an AD group called "ESX Admins" on a Windows Domain Controller
– Add users to that group
– Configure ESX/ESXi server’s "Directory Services"

If your ESX hosts and Active Directory Domain controllers are able to find each other via DNS, you’re ready to go to the next step of this setup. We need to create a group called “ESX Admins” and add the users with administrator permissions in vCenter to this group. When you choose a different name for the group, you will not be able to use Active Directory Authentication. I found this in the vsp_41_esx_server_config.pdf:

vCenter Server registers any selected Windows domain user or group through the process of assigning permissions. By default, all users who are members of the local Windows Administrators group on vCenter Server are granted the same access rights as any user assigned to the Administrator role. Users who are members of the Administrators group can log in as individuals and have full access.
Users who are in the Active Directory group ESX Admins are automatically assigned the Administrator role.

After creating the ESX Admins group it’s now time to join the ESX host to the Windows Domain. When you’re managing a small environment, you can do this with five a six mouse clicks per ESX host.

Continue reading “How To: Configure vSphere 4.1 Active Directory Authentication”

PowerCLI: Changing Advanced Configuration Settings for NFS


 go2.wordpress[1]  image_thumb[1] 

After reading Jase’s post http://www.jasemccarty.com/blog/?p=532 about setting the advanced configuration settings. I wanted to create a script and add it to the Community Powerpack (more info about the Powerpack here: http://www.virtu-al.net/2010/06/04/goodbye-virtu-al-hello-community/)

So I created two PowerCLI scripts to achieve this. You can see a short demo here:

 

This script will be added to the new version of the Powerpack.If you don’t want to wait until  the new version of the Community Powerpack comes online, you can use the following script to set the advanced settings on all of your ESX hosts:

param(
    [parameter(Mandatory = $true)]
    [string[]]$vCenter
)

Connect-VIServer $vCenter

$esxHosts = Get-VMHost | Sort Name
foreach($esx in $esxHosts){
    Write-Host "Updating TCP and NFS Advanced Configuration Settings on $esx"

    # Update TCP Settings
    if((Get-VMHostAdvancedConfiguration -VMHost $esx -Name Net.TcpipHeapSize).Values -ne "30"){
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name Net.TcpipHeapSize -Value 30 -Confirm:$false
    }
    if((Get-VMHostAdvancedConfiguration -VMHost $esx -Name Net.TcpipHeapMax).Values -ne "120"){
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name Net.TcpipHeapMax -Value 120 -Confirm:$false
    }

    # Update NFS Settings
    if((Get-VMHostAdvancedConfiguration -VMHost $esx -Name NFS.HeartbeatMaxFailures).Values -ne "10"){
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name NFS.HeartbeatMaxFailures -Value 10 -Confirm:$false
    }
    if((Get-VMHostAdvancedConfiguration -VMHost $esx -Name NFS.HeartbeatFrequency).Values -ne "12"){
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name NFS.HeartbeatFrequency -Value 12 -Confirm:$false
    }
    if((Get-VMHostAdvancedConfiguration -VMHost $esx -Name NFS.HeartbeatTimeout).Values -ne "5"){
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name NFS.HeartbeatTimeout -Value 5 -Confirm:$false
    }
    if((Get-VMHostAdvancedConfiguration -VMHost $esx -Name NFS.MaxVolumes).Values -ne "64"){
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name NFS.MaxVolumes -Value 64 -Confirm:$false
    }
}

 

You can start the script with the parameter –vCenter in my case this is vc01:

image

The script will generate the following output.

image

Note on the first ESX host I already changed the NFS.HeartbeatFrequency during the test of the cmdlets.

PowerCLI: Script to Schedule Memory and or vCPU up/downgrade


After creating the Restart-VMs.ps1 script, I also created a script to schedule vHardware changes. With this script, you’re able to upgrade or downgrade the amount of memory and or the amount of vCPU’s of a VM. Just lik the restart script, you can schedule this script and change the recommended parameters.

These are the parameters you need to supply to the script. The first two parameters are mandatory. When you supply all the parameters, you are able to add/remove Memory and add/remove vCPU’s.

-vCenter enter the vCenter server you want to connect to. It’s possible to connect to multiple vCenter servers.
-vmName enter the name of the VM you want
-MemoryMB enter the amount of memory you want to add or remove from the VM. Be sure you enter the amount in MB.
-MemoryOption Supply the option add or remove.
-CPUCount Enter the amount of vCPU’s you want to add or remove from the VM.
-CPUOption Supply the option add or remove.

This is how the script works.

  1. Connect to vCenter
  2. Shutdown the selected VM
  3. Add/remove memory and or vCPU’s
  4. Poweron the selected VM
  5. Disconnect vCenter

Now it’s time for an example. I have a VM called NAGIOS and needed to remove 512MB RAM and needed to add an extra vCPU. So I started the script with the following parameters:

.\Change-VM_Memory_CPU_Count.ps1 -vCenter vc01.ict-freak.local -vmName NAGIOS -MemoryMB 512 -MemoryOption Remove -CPUCount 1 -CPUOption Add

The VM is powered off and the memory is downgraded to 1024MB RAM and the total number of vCPU’s upgraded to 2.

image

You can download the script below.

Continue reading “PowerCLI: Script to Schedule Memory and or vCPU up/downgrade”

PowerCLI Schedule a restart job for one or multiple VM’s


I created the following script to schedule some restart jobs overnight. The goal for this script was to add some parameters so you don’t have to edit the script file itself to schedule it for another VM or a group of VM’s.

####################################################################
#
# Restart-VMs.ps1
# 
# -vCenter vCenter Server or Servers to connect to. 
# Example -vCenter "vc01","vc02"
# -vmName the VM or VMs to restart.
# Example -vmName "VM1" or -vmName "VM1","VM2"
# # Example: #.\Restart-VMs.ps1 -vCenter vc01.ict-freak.local -vmName "VM1","VM2" # # Version 1.0 May 2010 Arne Fokkema www.ict-freak.nl @afokkema # ##################################################################### param( [parameter(Mandatory = $true)] [string[]]$vCenter, [parameter(Mandatory = $true)] [string[]]$vmName ) $VIServer = Connect-VIServer $vCenter If ($VIServer.IsConnected -ne $true){ Write-Host "error connecting to $vCenter" -ForegroundColor Red exit } foreach($vm in $vmName){ Write-Host "Going to restart $vm" Restart-VMGuest -VM (Get-VM $vm) -Confirm:$false } Disconnect-VIServer -Confirm:$false

Let’s start to run the script from the PowerCLI console first:

image

I started the script without setting any of the parameters. Since these two parameters are necessary  to run the script, you will be asked to enter the parameters, before you can continue.

 

Now it’s time to schedule the script in Windows Server 2008. Just create a simple scheduled task with the following settings:

The first line below is the Program/script: setting. The second line is the Add arguments setting.

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe

-PSConsoleFile "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" " &  "C:\Scripts\Restart-VMs.ps1" -vCenter vc01 -vmName "VM1","VM2"

image

When you are going to use this script, be absolutely sure you are allowed to restart the VM’s you scheduled.

Release: PowerCLI Update Manager cmdlets


image

Just saw the news on Twitter. The PowerCLI Update Manager cmdlets are back!

Quote from the PowerCLI blog:

Cmdlet Name

Cmdlet Description

Attach-Baseline

Attaches baselines to the specified Template, VirtualMachine, VMHost, Cluster, Datacenter, Folder, and VApp objects.
Attaching a baseline to a container object such as a folder or datacenter transitively attaches the baseline to all objects in the container.

Detach-Baseline

Detaches baselines from the specified inventory objects.

Download-Patch

Downloads new patches into the Update Manager patch repository from the enabled patch download sources.

Get-Baseline

Retrieves the baselines specified by the provided cmdlet

parameters.

Get-Compliance

Retrieve baseline compliance data for the specified object of type Template, VirtualMachine, VMHost, Cluster, Datacenter, Folder, and VApp.

Get-Patch

Retrieves all available patches or those specified by the provided cmdlet parameters.

Get-PatchBaseline

Retrieves all patch baselines or those specified by the provided cmdlet parameters.

New-PatchBaseline

Creates a new patch baseline. Patch baselines can be applied to either hosts or virtual machines. Depending on the patch criteria you select, patch baselines can be either dynamic or static (fixed).

Remediate-Inventory

Remediates an inventory object against the specified baselines.

Remove-Baseline

Deletes the specified baselines from their servers. Before the

removal, the baselines are detached from all entities they have been attached to.

Scan-Inventory

Scans inventory objects for baselines attached to them.

Set-PatchBaseline

Modifies the properties of a patch baseline. You can specify explicitly the patches you want to include in the baseline through the IncludePatch parameter.

Stage-Patch

Initializes staging of patches. Staging allows you to download

patches from the Update Manager server to the ESX/ESXi hosts, without applying the patches immediately.

 

Download and more information can be found here: http://communities.vmware.com/

Release Notes can be found here: http://communities.vmware.com/docs/DOC-12075

The online manual can be found here: http://www.vmware.com/

 

You need to install PowerCLI 4 update 1 before you install the Update Manager cmdlets

PowerCLI: Return Datastore name by Canonical name


When you are troubleshooting an ESX host, you can see a lot off warnings in the VMKERNEL log:

Jan 29 16:15:34 esx02.ict-freak.local vmkernel: 9:23:45:33.917 cpu1:4210)WARNING: NMP: nmp_DeviceAttemptFailover:
Retry world failover device “t10.9454450000000000000000001000000056900000D0000000” – issuing command 0x4100041f0c00

But which datastore belongs to the Canonical name mentioned in the VMKERNEL log??

The following script will return the Datastore name. Thanks @Lucd22 for the help!!

$esxhost = "esx1.ict-freak.local"
$id = "t10.9454450000000000000000001000000056900000D0000000"

foreach($ds in (Get-VMHost $esxhost | `
    Get-Datastore | where{$_.Type -eq "vmfs"} | Get-View)){

    $ds.Info.Vmfs.Extent | %{
         if($_.DiskName -eq $id){
            Write-Host $ds.Info.Name $_.DiskName
        }
    }
}

The output will look like this:

image

Ok, this is a nice script to have in you toolbox, but I hear you think,  how do I add it to the VESI?.

First you need to create a new folder, if you don’t use any other Powerpack.

image

Give the folder a name. I used the name Personal scripts:

image

The next step is to add a new script node:

image

The last step is to paste the following code into the new created script node:

if ($global:defaultviservers) {
    $id = Read-Host "Enter the Canonical Name (naa.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)"
    foreach($esx in (Get-VMHost)){
        foreach($ds in (Get-VMHost $esx | Get-Datastore | ` 
        where{$_.Type -eq "vmfs"} | Get-View)){
            $Details = "" |Select-Object DataStore
                $ds.Info.Vmfs.Extent | %{
                 if($_.DiskName -eq $id){
                    $Details.DataStore = $ds.Info.Name
                }
               }
        }
        $Details.PSTypeNames.Clear()
        $Details
    }
}
Else {
    [System.Windows.Forms.MessageBox]::Show('You must connect to one or more hosts before you can use this node. Please click on the ''Managed Hosts'' node of the VMware PowerPack, connect to one or more of the servers you have configured there, and then try again.','Connection not established',[System.Windows.Forms.MessageBoxButtons]::OK,[System.Windows.Forms.MessageBoxIcon]::Information) | Out-Null
}

If you want to run this script, you have to connect to vCenter first. Open VMware – Managed Hosts:

image

Click on Add managed host… to add a server:

image

To connect to the new added vCenter server, press the connect under actions. To run the script click on the new create script node and enter a Canonical Name.

image

And the script will return the Datastore name:

image

Now you are able to convert the Canonical name to the Datastore Name.