Detach LUNs from Multiple ESXi Hosts Using Powercli

Hi there

Migrating an old VMWare Vcenter environment to newer vcsa 6.5 can be challenging. In the process I found myself doing other tasks like converting RDMs (Mapped Raw LUN) to .vmdk files.

Migrating RDMs attached to virtual machines on my Vcenter 5.5 environment to .vmdk disk files appeared like a tedious handy task especially when you have these LUNs attached to many ESXi hosts. With the help of powershell and Powercli the task becomes much easier.

I found it comfortable and safer to detach each LUN from all ESXi servers, so this script answers my current need and may be modified as needed. Im aware that it can still be improved and I hope to publish new and improved versions later.

The script asks for the “LUN canonicalName” and performs a Detach action on each Host from the list you provide.

You can find the LUN canonicalName here:LUN canonical name

Prepare a text file with the ESX servers list in c:\temp\esxList.txt, one in each line like so:


Run the script and enter the LUN canonicalName like seen in the above picture.

$CanonicalName = Read-Host "Enter LUN canonicalName"
vcName = "enter vcenter name here"
#get list of hosts
$hostslist = Get-Content "c:\temp\esxList.txt"

# Load VMware PowerShell Module (PowerCLI):
If ((Get-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null)
    Import-Module VMware.VimAutomation.Core

#check if connected to VC and connect if not
$viserver = $global:defaultviserver.Name
if ($viserver -ne $vcName) {
Connect-VIServer -Server vc55

#Start looping ESXi hosts and detach LUNs
foreach ($vmhost in $hostslist){

    write-host “Starting $vmhost”
    $esx = get-vmhost $vmhost
        $storSys = Get-View $esx.Extensiondata.ConfigManager.StorageSystem
        $lunUuid = (Get-ScsiLun -VmHost $VMHost | where {$_.CanonicalName -eq $CanonicalName}).ExtensionData.Uuid
        "Detaching $lunUuid"

Using Powershell to Trace the Source of Account Lockouts in Active Directory

How to: track the source of user account lockout using Powershell

In my last post about how to Find the source of Account Lockouts in Active Directory I showed a way to filter the event viewer security log with a nifty XML query.

In this post I recomposed (Source:Ian Farr) a Powershell script which will ask for the locked user account name and then will scan the active directory DCs security log for relevant events and will present the user lock time and source of the lock out like so:

locked user powershell script

Continue reading Using Powershell to Trace the Source of Account Lockouts in Active Directory

Find the source of Account Lockouts in Active Directory

How to: Find the source of Account Lockouts in Active Directory

It is a very common problem in Active Directory when Users change their password in a domain environment, they might get locked out repeatedly and it can be a frustrating process to identify the source of the lockout.

Try the following steps to track the locked out user and also find the source of AD account lockouts. This procedure assume that you know the username which is locked out.

I recommend doing this procedure on ALL your Domain Controllers, not only your PDC Server, just to be sure you didn’t miss a lockout event. Continue reading Find the source of Account Lockouts in Active Directory

Power off the virtual machine in an ESXi host

Ways to power off a virtual machine in an ESXi host using the command line


Using the ESXi command-line utility vim-cmd to power off the virtual machine

  1. SSH into your ESXi server
  2. Get a list of all registered virtual machines, identified by their VMID, Display Name and path to the .vmx configuration file by running this command: vim-cmd vmsvc/getallvms
    vim-cmd vmsvc/getallvms

  3. Get the current state of a virtual machine by running this command:
    vim-cmd vmsvc/power.getstate VMID

  4. Shutdown the virtual machine using the VMID found in Step 2 and run this command:
    vim-cmd vmsvc/power.shutdown VMID

  5. If the virtual machine fails to shut down, run this command:
    vim-cmd vmsvc/ VMID

Continue reading Power off the virtual machine in an ESXi host

SCCM Report – Count All Computers by Model

How to create a MS Configuration manager report that will Count All Computers for each Model

This guide will show you how to create a report in Microsoft System Center Configuration Manager 2012(R2) / Current branch 1702. In this example we will be creating a report which lists all system models and displays a count of each model.

SCCM 2012 (last checked on build 1702) does not have a prebuilt report that will simply return a list of all the distinct manufacturer/model numbers for all the computers in the environment and a count of each type. Continue reading SCCM Report – Count All Computers by Model

System Administrators Tricks