VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

log_script_powercli

pastedImage_0.png

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"

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaks iam checking this.but are we not calling $ds.name as ps object ??

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks Ia m checking.

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

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?

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos