I am trying to write a script that returns the datastore ID. For example
____________________________________________________________
$datastore = Get-Datastore | Where-Object {$_.Name -notlike 'local'}
ForEach ($ds in $datastore) {
$Id = $ds | select Id
Write-Host $Id
}
____________________________________________________________
The output is:
@{Id=Datastore-datastore-15}
I would like the output to be either the number 15 or datastore-15. I am sure there is some string manipulation I can do just need to figure that out, but what I was also wondering is there a way to return this information without having to manipulate the output?
If you're using PowerCLI 4.1 you can do that :
$datastore = Get-Datastore | Where-Object {$_.Name -notlike '*local*'} ForEach ($ds in $datastore) { $dsMoRef = New-Object VMware.Vim.ManagedObjectReference -ArgumentList $ds.Id Write-Host $dsMoRef.Value }
Regards,
Yasen Kalchev
PowerCLI Dev Team
If you're using PowerCLI 4.1 you can do that :
$datastore = Get-Datastore | Where-Object {$_.Name -notlike '*local*'} ForEach ($ds in $datastore) { $dsMoRef = New-Object VMware.Vim.ManagedObjectReference -ArgumentList $ds.Id Write-Host $dsMoRef.Value }
Regards,
Yasen Kalchev
PowerCLI Dev Team
Thank you it worked just like I wanted.
Yasen,
Thank you, it returned exactly what I was looking for.
You can also try
Get-Datastore | Where-Object {$_.Name -notlike 'local'} | select -ExpandProperty ID