Hi Luc,
trying to get log files (vmware.log from vm and vmkernel from esxi)
could you check the line for new-psdrive as i dont get location parameter .
also elseif loop is not working if i give only first part of esxi name like esx-01a only in "esx-01a.corp.local"
The Location parameter requires a Datastore object, not the name as a String.
For the ESXi test, try like this
$entity = Read-Host "Which entity?"
if((Get-VM -ErrorAction SilentlyContinue).Name -contains $entity){
Write-Host "It's a VM"
$vm = Get-VM -Name $entity
$ds = Get-Datastore -RelatedObject $vm
New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root '\' | Out-Null
Get-ChildItem -Path DS:\
Remove-PSDrive -Name DS -Confirm:$false
}
elseif(((Get-VMHost).Name | %{$_.Split('.')[0]}) -contains $entity){
Write-Host "It's an ESXi"
}
PS: please do not use screenshots of code, I like to copy/paste code :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The Location parameter requires a Datastore object, not the name as a String.
For the ESXi test, try like this
$entity = Read-Host "Which entity?"
if((Get-VM -ErrorAction SilentlyContinue).Name -contains $entity){
Write-Host "It's a VM"
$vm = Get-VM -Name $entity
$ds = Get-Datastore -RelatedObject $vm
New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root '\' | Out-Null
Get-ChildItem -Path DS:\
Remove-PSDrive -Name DS -Confirm:$false
}
elseif(((Get-VMHost).Name | %{$_.Split('.')[0]}) -contains $entity){
Write-Host "It's an ESXi"
}
PS: please do not use screenshots of code, I like to copy/paste code :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thnaks iam checking this.but are we not calling $ds.name as ps object ??
For the New-PSDrive cmdlet, which is not a PowerCLI cmdlet, there is no OBN, you have to provide the datastore object
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Ia m checking.
Thanks Luc,
this works fine but even after disconnecting DS iam still getiing folowing under get-psdrive output.
and i stronly believe that new-psdrive wont cause anything to datastore .its just a way of presenting datastore as psdrive .is that correct?
Yes, when you load the PowerCLI modules, these drives are created.
Even without doing a Connect-VIServer.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference