sg0133
Contributor
Contributor

powermt license check

Jump to solution

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

0 Kudos
30 Replies
LucD
Leadership
Leadership

Whatever makes your script work is fine with me Smiley Happy

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. Smiley Sad


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
sg0133
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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 ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
sg0133
Contributor
Contributor

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.

0 Kudos
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

sg0133
Contributor
Contributor

You are LORD. Yes this time it is working.

Both for lincensed & unlicensed servers.

Thanks a lot Luc..Smiley Happy

0 Kudos
Nawals
Expert
Expert

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.

NKS Please Mark Helpful/correct if my answer resolve your query.
0 Kudos
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Nawals
Expert
Expert

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.

NKS Please Mark Helpful/correct if my answer resolve your query.
0 Kudos
LucD
Leadership
Leadership

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

I corrected the code above, give it another try.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Nawals
Expert
Expert

Thanks. Will try it.

NKS Please Mark Helpful/correct if my answer resolve your query.
0 Kudos