Tuesday, June 21, 2011

Remove HBAs from Navisphere

Remove all Registered, and Logged Out HBAs
NaviSECCli.exe -user emc -password emc -scope 0 -h tkj1506ds01 port -removehba -all

Remove a specific HBA (logged in or out)
NaviSECCli.exe -user emc -password emc -scope 0 -h tkj1506ds01 port -removehba -hbauid 50:01:39:71:00:0F:81:46:50:01:39:70:00:0F:81:46

Wednesday, June 15, 2011

Gathering VM inventory via PowerShell

We are moving several VMs from an ESX4.0 environment to a ESX4.1 environment and performing tools/HW upgrades at the same time. The two environments report to different Virtual Center servers, so we need to collect various information about the VMs prior to migrating them. Below is a combination of several scripts I found online to provide me the Folder Path, VM version, and Network information from all VMs in a VC. Its not perfect, but it provides the preliminary information needed to begin moving VMs

$Information = @()
Foreach ($VM in (Get-VM | Sort Name)){
$VMv= $VM | Get-View
$MyDetails = "" | Select-Object VMName,VMXLocation,FolderPath,Version,NetworkName
$MyDetails.VMName = $VMv.Name
$MyDetails.VMXLocation = $VMv.Config.Files.VmPathName
$current = get-view $vmv.Parent
$path = $vmv.Name
do {
 $parent = $current
 if($parent.name -ne "vm"){$path = $parent.Name + "\" + $path}
 $current = Get-View $current.Parent
} while ($current.Parent -ne $null)
$MyDetails.FolderPath = $path
$MyDetails.Version = $VM.Version
#$MyDetails.NetworkName = foreach ($nic in $VM.Guest.NICs) { $nic.Connected.tostring() +" "+ $nic.NetworkName +" "+ $nic.IPAddress }
foreach ($nic in $VM.Guest.NICs) { $MyDetails.NetworkName += $nic.Connected.tostring() +","+ $nic.NetworkName +","+ $nic.IPAddress +"," }
$Information += $MyDetails
$Information | Export-Csv d:\temp\output.csv

Managing DNS records via PowerShell

I am always looking for ways to automate tasks, and I make it my goal to only use GUI interfaces if tasks are infrequent or there is no other choice. We are in process of reconfiguring several of our VMs, and as such are creating static DNS entries for the systems. I was very excited when I found this post with the below script:http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/13/manage-dns-in-a-windows-environment-by-using-powershell.aspx

    function new-dnsrecord {
    ## check DNS server contactable
        if (-not (Test-Connection -ComputerName $server)){Throw "DNS server not found"}
    ## split the server fqdn and address
        $srvr = $server -split "\."
        $addr = $address -split "\."
        $rec = [WmiClass]"\\$($srvr[0])\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord" 
    ## create records
    ## A
        if ($arec){
            $text = "$computer IN A $address" 
            $rec.CreateInstanceFromTextRepresentation($server, $fzone, $text) 
    ## CNAME
        if ($cname){
            $text = "$alias IN CNAME $computer" 
            $rec.CreateInstanceFromTextRepresentation($server, $fzone, $text) 
    ## PTR
        if ($ptr){
            $text = "$($addr[3]).$rzone IN PTR $computer" 
            $rec.CreateInstanceFromTextRepresentation($server, $rzone, $text) 
    ## MX
        if ($mx){
            $text = "$maildomain IN MX $priority $computer" 
            $rec.CreateInstanceFromTextRepresentation($server, $fzone, $text)