Automation

 View Only
Expand all | Collapse all

powermt license check

  • 1.  powermt license check

    Posted Mar 22, 2013 09:36 AM
      |   view attached

    Hi Experts ,

    I was trying to script the process of EMC PowerPath license check for all the ESXi servers in our environment.
    The PowerPath is installed but in some servers it is not registered.The installation path is like this
    /opt/emc/powerpath/bin/powermt check_registration

    So i want to redirect the output to a file or just the word "unlicensed" with respect to that host.

    $VMHosts = Get-VMHost
    $VICreds = Get-VICredentialStoreItem -File D:RootCreds.xlsx
    $LicenseChk = & '/opt/emc/powerpath/bin/powermt check_registration' host=$($VMHost.name) username=$($VICreds.User) password=$($VICreds.Password)

    I tried to script in this way but it is failing with below errors.

    If anyone has better suggestions than this way please advice.

    Thanks in Advance.

    Regards

    Sourav

    Attachment(s)

    txt
    errors.txt   1 KB 1 version


  • 2.  RE: powermt license check

    Posted Mar 22, 2013 09:45 AM

    You will have to use a SSH session to the ESX console to execute the command, the PowerShell call operator (&) will not work.

    Most users go for plink.exe that is part of the PuTTY suite.

    Alan just posted about using plink for an SSH session, see SSH PowerShell tricks with plink.exe

    The first error you get seems to indicate you have a problem with the credential file you are trying to access.



  • 3.  RE: powermt license check

    Posted Mar 28, 2013 03:44 AM

    Hi Luc ,

    Thanks for pointing towards Plink. I was going through some of your's & Alan's old notes regarding executing cmds through plink.

    I tried using this script for a single host & to grep the "State" status to a csv file for that particular host printing the hostname & "state" status.

    Below is my script i tried to use :

    $ExportFilePath = "C:\HostNicInfo.csv"
    $PuttyUser = "root"
    $PuttyPwd = "passwd"
    $hostlist = "esx-test-120"
    $Plink = "C:\plink.exe"
    $PlinkOptions = " -v -batch -pw $PuttyPwd"
    $cmd1 = '/opt/emc/powerpath/bin/powermt check_registration '
    $RCommand = '"' + $cmd1 + '"'
    $command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $hostlist + " " + $RCommand
    $msg = Invoke-Expression -command $command

    Write-Host "Connecting to: " $hostlist -ForegroundColor Green
    $HostInfo.license = ($Message[0] -split "State: ")[1]
    $Report += $HostInfo.license
    $Report | Export-Csv $ExportFilePath -NoTypeInformation

    The output of the $cmd1 if i execute manually gives me like this below :

    Type : served (counted)

    State : licensed

    Registered To : ACTIVATED

    Issue Date : xx-xx-xx

    Feature : PowerPathMP

    Feature Version : 5.4

    Registering Svr : xxxxxxxx

    License Count : xxxx

    Overdraft Count : xxx

    License Server : xxxxxxxx

    In the above output i tried for "State" status. But i am getting the below errors while executing the above script.

    Looking up host "esx-test-120"
    Connecting to 10.182.79.63 port 22
    Server version: SSH-2.0-OpenSSH_5.6
    Using SSH protocol version 2
    We claim version: SSH-2.0-PuTTY_Release_0.62
    Doing Diffie-Hellman group exchange
    Doing Diffie-Hellman key exchange with hash SHA-256
    The server's host key is not cached in the registry. You
    have no guarantee that the server is the computer you
    think it is.
    The server's rsa2 key fingerprint is:
    ssh-rsa 2048 54:d5:1a:c3:61:b0:2e:c1:43:cc:eb:06:29:2c:5c:86
    Connection abandoned.
    Disconnected: User aborted at host key verification
    Connecting to:  esx-test-120
    Cannot index into a null array.
    At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\abc.ps1:13 char:31
    + $HostInfo.license = ($Message[ <<<< 0] -split "State: ")[1]
        + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
        + FullyQualifiedErrorId : NullArray

    Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
    At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\abc.ps1:15 char:21
    + $Report | Export-Csv <<<<  $ExportFilePath -NoTypeInformation
        + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

    Please share your advices how to make it work because in future i want it to import a server list instead of single server.

    Thanks in Advance.



  • 4.  RE: powermt license check

    Posted Mar 28, 2013 08:13 AM

    When you establish the first SSH connection to a host, plink asks you to accept the host key.

    Now unfortunately, there is no switch on the plink command to automate this.

    But Alan has a simple trick to do this, see his SSH PowerShell tricks with plink.exe post.



  • 5.  RE: powermt license check

    Posted Mar 29, 2013 01:54 PM


    Hi Luc ,

    Thanks for your advice. The host key problem is resolved now.

    But i am getting below error while extracting the output from the cmd :

    Cannot index into a null array.
    At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\abc.ps1:13 char:31
    + $HostInfo.license = ($Message[ <<<< 0] -split "State: ")[1]
        + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
        + FullyQualifiedErrorId : NullArray

    Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
    At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\abc.ps1:15 char:21
    + $Report | Export-Csv <<<<  $ExportFilePath -NoTypeInformation
        + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

    Thanks in Advance.



  • 6.  RE: powermt license check

    Posted Mar 29, 2013 05:16 PM

    Is that variablename correct ?

    ...

    $msg = Invoke-Expression -command $commandWrite-Host "Connecting to: "

    $hostlist -ForegroundColor Green
    $HostInfo.license = ($Message[0] -split "State: ")[1]

    ...



  • 7.  RE: powermt license check

    Posted Apr 01, 2013 03:57 AM

    Thanks Luc , i modified it , still now i am getting this below error :

    Connecting to:  esxtest-120 Property 'licensed' cannot be found on this object; make sure it exists and is settable.
    At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\abc.ps1:12 char:11
    + $HostInfo. <<<< licensed = ($msg[0] -split "State: ")[1]
        + CategoryInfo          : InvalidOperation: (licensed:String) [], RuntimeException
        + FullyQualifiedErrorId : PropertyNotFound

    Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
    At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\abc.ps1:14 char:21
    + $Report | Export-Csv <<<<  $ExportFilePath -NoTypeInformation
        + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand



  • 8.  RE: powermt license check

    Posted Apr 01, 2013 06:01 AM

    Where did you define the variable $HostInfo ?

    Is the script above the complete script you are trying to run ?

    Perhaps let us know from where you got it ? There seem to be parts missing.



  • 9.  RE: powermt license check

    Posted Apr 03, 2013 01:24 AM

    Hi Luc ,

    I modified the script from Yuri which reports the NIC's firmware's from all the ESXi hosts . Please find the link below :

    https://yuridejager.wordpress.com/2012/04/18/list-all-physical-nics-driver-and-firmware-information-of-all-your-esxi-4-1-hosts-using-powercli-4-1/

    The script i am using is the below one :

    $ExportFilePath = "C:\Hostpathinfo.csv"
    $PuttyUser = "root"
    $PuttyPwd = "passwd123"
    $hostlist = "esx-test-123"
    $Plink = "echo Y |C:\plink.exe"
    $PlinkOptions = " -v -pw $PuttyPwd"
    $cmd1 = "./opt/emc/powerpath/bin/powermt check_registration | grep licensed"
    $RCommand = '"' + $cmd1 + '"'
    $command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $hostlist + " " + $RCommand
    $msg = Invoke-Expression -command $command
    Write-Host "Connecting to: " $hostlist -ForegroundColor Green
    $HostInfo.licensed = ($msg[0] -split "State: ")[1]
    $Report += $HostInfo.licensed
    $Report | Export-Csv $ExportFilePath -NoTypeInformation

    Either of these can be used to get output .The actual output of the command when i am using manually is below :

    # ./opt/emc/powerpath/bin/powermt check_registration | grep licensed
          State           : licensed

    # ./opt/emc/powerpath/bin/powermt check_registration

          PowerPath License Information:
          ------------------------------

          Host ID         : xx-xx-xx-xx
          Type            : served (counted)
          State           : licensed
          Registered To   : ACTIVATED
          Issue Date      : 21-Jul-2010
          Feature         : PowerPathMP
          Feature Version : 5.4
          Registering Svr : xx-xx-xx-xx
          License Count   : xx
          Overdraft Count : xx



  • 10.  RE: powermt license check

    Posted Apr 03, 2013 05:24 AM

    In this line

    $HostInfo.licensed = ($msg[0] -split "State: ")[1]

    you assign a value to the 'licensed' property of the object in the variable $HostInfo.

    But that object in $HostInfo doesn't seem to be defined anywhere. That explains the error message.

    You should add this line in your script

    $HostInfo = {} | Select HostName,ESXVersion,Cluster,pNic,DriverName,DriverVersion,DriverFirmware,Licensed

    That define the object and its properties, more specifically the Licensed property..



  • 11.  RE: powermt license check

    Posted Apr 04, 2013 06:44 AM

    Hi Luc ,

    I am not getting the expected output. The csv file is containing only the hostname & State not whether it is licensed or unlicensed.

    I am suspecting may be the format of the output which i am getting is responsible for that.There is lot blank space on the left side.I am attaching

    the manual output from the command.


    # ./opt/emc/powerpath/bin/powermt check_registration

        
        
          PowerPath License Information:
          ------------------------------

          Host ID         : xx-xx-xx-xx
          Type            : served (counted)
          State           : licensed
          Registered To   : ACTIVATED
          Issue Date      : 11-Jul-2011
          Feature         : PowerPathMP
          Feature Version : 5.4
          Registering Svr : xx-xx-xx-xx
          License Count   : xx
          Overdraft Count : xx
          License Server  : xx-xx-xx-xx

          Days until expiration : (non-expiring)

          License search path: /etc/emc:/etc/emc/licenses:/opt/EMCpower:/opt/EMCpower/licenses

    ===========================================Script===========================================

    $ExportFilePath = "C:\HostNicInfo.csv"
    $PuttyUser = "root"
    $PuttyPwd = "passwd123"
    $hostlist = "esx-test-120"
    $Plink = "echo Y |C:\plink.exe"
    $PlinkOptions = " -v -pw $PuttyPwd"
    $cmd0 = "./opt/emc/powerpath/bin/powermt check_registration"
    $Report = @()
    $Message = ""
    $HostInfo = {} | Select HostName,State
    $HostInfo.HostName = $hostlist
    Write-Host "Connecting to: " $hostlist -ForegroundColor Green
    $command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $hostlist + " " +$cmd0
    $Message = Invoke-Expression -command $command
    $HostInfo.State = ($Message[1] -split "State : ")[1]
    $Report += $HostInfo
    $Report | Export-Csv $ExportFilePath -NoTypeInformation

    Also i have an query if i used 'grep' command in $cmd0 it says it is not a valid cmdlet. Is there any way i can use this way


    $cmd0 = "./opt/emc/powerpath/bin/powermt check_registration | grep State"
          State           : licensed


    Thanks in Advance.



  • 12.  RE: powermt license check

    Posted Apr 04, 2013 11:41 AM

    Try this version that uses a RegEx expression to find the State field.

    $mask = [regex]"State\s*:\s(?<status>\w+?)\s"
    $ExportFilePath = "C:\HostNicInfo.csv" 
    $PuttyUser
    = "root"
    $PuttyPwd = "passwd123"
    $hostlist = "esx-test-120"
    $Plink
    = "echo Y |C:\plink.exe"
    $PlinkOptions
    = " -v -pw $PuttyPwd"
    $cmd0 = "./opt/emc/powerpath/bin/powermt check_registration"
    $Report = @() $Message = ""
    $HostInfo
    = {} | Select HostName,State
    $HostInfo.HostName = $hostlist
    Write-Host "Connecting to: " $hostlist -ForegroundColor Green
    $command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $hostlist + " " +$cmd0
    $Message
    = Invoke-Expression -command $command
    $mask
    .Matches($command) | Out-Null
    $HostInfo
    .State = $Matches["status"] $Report += $HostInfo
    $Report | Export-Csv $ExportFilePath -NoTypeInformation


  • 13.  RE: powermt license check

    Posted Apr 05, 2013 06:50 AM

    Hi Luc ,

    I am getting below error , i am executing in the below format :

    ./Scripts/pp.ps1 -status licensed

    Cannot index into a null array.
    At C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\pp.ps1:17 char:28
    + $HostInfo.State = $Matches[ <<<< "status"]
        + CategoryInfo          : InvalidOperation: (status:String) [], RuntimeException
        + FullyQualifiedErrorId : NullArray

    Regards

    Sourav



  • 14.  RE: powermt license check

    Posted Apr 05, 2013 08:13 AM

    Try this updated version

    $mask = "State\s*:\s(?<status>\w+?)\s" 
    $ExportFilePath
    = "C:\HostNicInfo.csv" $PuttyUser = "root"
    $PuttyPwd
    = "passwd123"
    $hostlist
    = "esx-test-120" $Plink = "echo Y |C:\plink.exe"
    $PlinkOptions = " -v -pw $PuttyPwd"
    $cmd0 = "./opt/emc/powerpath/bin/powermt check_registration"
    $Report = @() $Message = ""$HostInfo = {} | Select HostName,State
    $HostInfo
    .HostName = $hostlist
    Write-Host
    "Connecting to: " $hostlist -ForegroundColor Green
    $command
    = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $hostlist + " " +$cmd0
    $Message
    = Invoke-Expression -command $command
    $result
    = $Message | Select-String -Pattern $mask
    if
    ($result){   $HostInfo.State = $result.Matches[0].Groups["status"].Value
    } else{   $HostInfo.State = "Status not found"
    }
    $Report += $HostInfo
    $Report
    | Export-Csv $ExportFilePath -NoTypeInformation


  • 15.  RE: powermt license check

    Posted Apr 05, 2013 09:29 AM

    Hi Luc ,

    It is not  going inside the "if " loop. It is always printing the "Sate" as Status not found.

    HostName       State
    esx-test-120 Status not found

    esx-test-127 Status not found



  • 16.  RE: powermt license check

    Posted Apr 08, 2013 07:33 AM

    Hi Luc ,

    I am executing the script as .\Scripts\pp.ps1. I tried with one server with PowerPath license installed & another one with licensed installed. But both are showing State as "Status not found".

    Regards

    Sourav



  • 17.  RE: powermt license check

    Posted Apr 08, 2013 09:57 AM

    Can you attach the output from the command in a file ?

    I might be using an incorrect regex expression.



  • 18.  RE: powermt license check

    Posted Apr 08, 2013 11:19 AM
      |   view attached

    Hi Luc ,

    Please powermt check_registration output in attachment.

    Regards

    Sou

    Attachment(s)

    txt
    pp.out.txt   596 B 1 version


  • 19.  RE: powermt license check

    Posted Apr 08, 2013 07:24 PM

    Slight change, try it like this

    $mask = [regex]"State\s*:\s(?<status>\w+?)\s"
    $ExportFilePath = "C:\HostNicInfo.csv" $PuttyUser = "root"
    $PuttyPwd = "passwd123"
    $hostlist = "esx-test-120" $Plink = "echo Y |C:\plink.exe"
    $PlinkOptions = " -v -pw $PuttyPwd"
    $cmd0 = "./opt/emc/powerpath/bin/powermt check_registration"
    $Report
    = @() $Message = ""$HostInfo = {} | Select HostName,State
    $HostInfo
    .HostName = $hostlist
    Write-Host "Connecting to: " $hostlist -ForegroundColor Green
    $command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $hostlist + " " +$cmd0
    $Message
    = Invoke-Expression -command $command
    $HostInfo
    .State = $Message | Select-String -Pattern $mask | Select -ExpandProperty Matches | %{$_.Groups["status"].Value} $Report += $HostInfo
    $Report | Export-Csv $ExportFilePath -NoTypeInformation


  • 20.  RE: powermt license check

    Posted Apr 09, 2013 08:24 AM

    Hi Luc ,

    No luck , there is no output for the State status.

    Do you think of any other way around we can try to get this status. Or can we use

    $cmd0 = "./opt/emc/powerpath/bin/powermt check_registration | grep -i State"

    Because when i use grep cmd manually i get the output like

          State           : licensed

    Please let me know your thoughts.

    Regards

    Sou



  • 21.  RE: powermt license check

    Posted Apr 09, 2013 08:31 AM

    Whatever makes your script work is fine with me :smileyhappy:

    Must be something strange in the output.

    And I can only test with the output text file since I don't have PowerPath I'm afraid. :smileysad:



  • 22.  RE: powermt license check

    Posted Apr 09, 2013 08:40 AM

    But when i am using grep in $cmd0 , it gives me error like this below :

    The term 'grep' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
    that the path is correct and try again.
    At line:1 char:106
    + C:\plink.exe  -v -pw passwd123 root@esx-test-127 ./opt/emc/powerpath/bin/powermt check_registration |grep <<<<  -i State
        + CategoryInfo          : ObjectNotFound: (grep:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

    Is there anyway i can use grep in my $cmd0.

    Regards

    Sou



  • 23.  RE: powermt license check

    Posted Apr 09, 2013 08:43 AM

    I'm confused now, I thought you said the grep command returned the corretc result.

    Or was that done manually from a TTY session to the ESXi server ?



  • 24.  RE: powermt license check

    Posted Apr 09, 2013 08:51 AM

    grep command returns the correct value when i execute it manually , even throgh plink also. But when i put grep in the script it fails to execute saying the above errors.



  • 25.  RE: powermt license check
    Best Answer

    Posted Apr 09, 2013 11:11 AM

    Ok, I simplified the script, espacially the RegEx part, even further.

    Let me know if this produces the correct results ?

    $ExportFilePath = "C:\HostNicInfo.csv" 
    $PuttyUser = "root" 
    $PuttyPwd
    = "passwd123"
    $hostlist
    = "esx-test-120" $Plink = "echo Y |C:\plink.exe"
    $PlinkOptions
    = " -v -pw $PuttyPwd"
    $cmd0
    = "./opt/emc/powerpath/bin/powermt check_registration"
    $Report
    = @() $HostInfo = {} | Select HostName,State
    Write-Host "Connecting to: " $hostlist -ForegroundColor Green
    $command
    = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $hostlist + " " +$cmd0
    $Message
    = Invoke-Expression -command $command
    if($message -match "State\s*:\s*licensed"){   $HostInfo.State = "licensed" } else{   $HostInfo.State = "licensed" } $HostInfo.HostName = $hostlist
    $Report
    += $HostInfo
    $Report
    | Export-Csv $ExportFilePath -NoTypeInformation


  • 26.  RE: powermt license check

    Posted Apr 09, 2013 12:48 PM

    You are LORD. Yes this time it is working.

    Both for lincensed & unlicensed servers.

    Thanks a lot Luc..:smileyhappy:



  • 27.  RE: powermt license check

    Posted Jan 09, 2018 08:20 AM

    Hi Luc,

    I have run this script for one host getting the output showing license.However, I have multiples ESXi hosts and each ESXi host have different different root password. How can I specify the ESXi hosts name and root password in script to get the Power Path licence status.



  • 28.  RE: powermt license check

    Posted Jan 09, 2018 08:33 AM

    You could store that info in an array, something like this

    $targets = @(

        @{

            VMHostName = 'esx1'

            Pswd = 'pswd1'

        },

        @{

            VMHostName = 'esx2'

            Pswd = 'pswd2'

        }

    )

    $ExportFilePath = "C:\HostNicInfo.csv"

    $PuttyUser = "root"

    $Report = @()

    foreach($row in $targets){

        $hostlist = $row.VMHostName

        $Plink = "echo Y |C:\plink.exe"

        $PlinkOptions = " -v -pw $($row.Pswd)"

        $cmd0 = "./opt/emc/powerpath/bin/powermt check_registration"

        $HostInfo = {} | Select HostName,State

        Write-Host "Connecting to: " $hostlist -ForegroundColor Green

        $command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $hostlist + " " +$cmd0

        $Message = Invoke-Expression -command $command

        if($message -match "State\s*:\s*licensed"){

            $HostInfo.State = "licensed"

        }

        else{

            $HostInfo.State = "na"

        }

        $HostInfo.HostName = $hostlist

        $Report += $HostInfo

    }

    $Report | Export-Csv $ExportFilePath -NoTypeInformation



  • 29.  RE: powermt license check

    Posted Jan 10, 2018 08:25 AM

    Hi Luc,

    When I run the script it will show EMC PP license status "Licensed" However, some ESXi hosts don't have EMC PP license but showing licensed it will show unlicensed right? can you please help me on this to get the correct report.



  • 30.  RE: powermt license check

    Posted Jan 10, 2018 08:43 AM

    There was an error in the if-then-else, both branches resulted in "licensed".

    I corrected the code above, give it another try.



  • 31.  RE: powermt license check

    Posted Jan 10, 2018 09:09 AM

    Thanks. Will try it.