Normally I used to login to each esxi host and run the below command
esxcfg-volume -M xxxxx(datastorename). Is there any way to combine this command with powercli to run on clusters or all esxi hosts. Please assist
Have a look at Solved: Power CLI equivalent to esxcfg-volume -M - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Lucd,
Nice to see you back,
Sorry the link which you have posted doesn't seems to open. Could you please post the script here if its handy.. will be really helpful
1.first connect to esxi
2.run the command esxcfg-volume -M xxxx(datastorename)
3. exit from esxi
That link works for me.
So you still want to use the esxcfg-volume command, but then from PowerCLI?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Lucd,
Am not sure could be my browser issue or some other..
yeah exactly the same.. need to use esxcfg-volume -M command with powercli for multiple hosts
Or even alternate commands equivalent to esxcfg-volume -M
Then you could use the Posh-SSH module to set up an SSH session and via that session give the command.
See my Use Posh-SSH instead of PuTTY dive.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I would try using POSH-SSH.
Can we use esxcli commands to do this activity
Yes, you can.
Use Get-EsxCli and then the call the mount method
$dsName = 'MyDS'
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.storage.filesystem.mount.Invoke(@{volumelabel=$dsName})
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Lucd,
When i used the below ESXCLI script for mounting the DS getting the below error
"Index( zero based) must be greater than or equal to zero and less than the size of the argument". Can this be sorted.
How did you run that?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$dsName = 'MyDS'
Get-VMHost -Name xxxx -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $_ -V2
$esxcli.storage.filesystem.mount.Invoke(@{volumelable=$dsName})
}
Hi Lucd,
I ran in the above method by providing DS name and individual host name and save it as.ps1
That should be volumelabel instead of volumelable
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i have corrected that as well and tried.. same result
Can you show me the actual script you're using (not a copy of my code)?
And a screenshot of the run.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I used the same script below and added datastore name and esx name and changed volume label..thats all
$dsName = 'MyDS'
Get-VMHost -Name xxxxx(esxname) -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.storage.filesystem.mount.Invoke(@{volumelabel=$dsName})
}
below is the screenshot attached
Even this command gives me the proper output with ds name which needs to be mapped.
$esxcli.storage.vmfs.snapshot.list.invoke()
You don't seem to be running this from a .ps1 file but line-by-line from the PS prompt.
That would mean the pipeline variable is not working.
If you can't give me the complete run you did, I'm afraid I can't help you
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Lucd,
Am running from a PS prompt. Initially I followed ur one of the blog which has the below command to pull the DS list which has to be mounted
$esxcli.storage.vmfs.snapshot.list.invoke() --> with this i was able to get the output of 2 DS which has to be mounted
$esxcli.storage.vmfs.snapshot.mount.invoke(@{volumelabel=$dsName}) --> post I tried with this and it worked mounting the DS to the host
Thanks for this..
I am having 100+ esxi host and am planning to run the below script. How can i add one more DS name in this.Pls comment or modify if anything needed.
=======
$esxcli = Get-EsxCli -VMHost (get-content c:\iso\hostnames.txt) - V2
$esxcli.storage.vmfs.snapshot.mount.invoke(@{volumelabel=$dsName})
and how can i pull the report which are the hosts got mapped in it
That is basically the same as the earlier solution I gave.
It adds the creation of an object for each ESXi node, which is then at the end saved to a CSV file.
Run this in a .ps1 file, not line-by-line from a PS prompt.
$dsName = 'your-DS-name'
Get-VMHost -Name (Get-Content -Path c:\iso\hostnames.txt) -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx - V2
$esxcli.storage.vmfs.snapshot.mount.invoke(@{volumelabel=$dsName})
New-Object -TypeName PSObject -Property @{
VMHost = $esx.Name
Datastore = $dsName
}
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference