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
Whatever makes your script work is fine with me
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
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.
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
You are LORD. Yes this time it is working.
Both for lincensed & unlicensed servers.
Thanks a lot Luc..
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.
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
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.
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
Thanks. Will try it.