VMware Cloud Community
johndavidd
Enthusiast
Enthusiast

Setting dir vmstores:\ to a variable

When I connect to a VC and run the following command I get an output...

dir vmstores:\ -Recurse -Include *-??????.vmdk

However, if I set this to a variable, the variable displays nothing

$snaps = dir vmstores:\ -Recurse -Include *-??????.vmdk

Any ideas?

My workaround for now is to export it out to a CSV then re-import it to work with it as a PS object...

0 Kudos
8 Replies
LucD
Leadership
Leadership

That seems to work for me.

Which PowerCLI version are you using ? Do a Get-PowerCLIVersion.

Are you doing this from the PowerCLI prompt ?

Perhaps you add a screenshot of the commands you executed ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
johndavidd
Enthusiast
Enthusiast

Yes, I'm running it from a prompt..I've tried from several different PowerCLI Versions. Current version is below..

VMware vSphere PowerCLI 5.0.1 build 581491

Screenshot attached

Capture.JPG

0 Kudos
LucD
Leadership
Leadership

That works for me as well, only difference is that I tested in a PowerCLI 5.1 R2 version.

Did you try that version as well ?

Any reason why you stick with this older version ?

Try leaving out the Select-Object when you assign the result to a variable. Do you get any data in the variable that way ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
johndavidd
Enthusiast
Enthusiast

Ran it on 5.1 R2

$files = dir vmstores:\ -Recurse

$files variable yields nothing ... though without the variable I get info.

:smileyconfused:

0 Kudos
LucD
Leadership
Leadership

Very strange :smileyconfused:

Let's check some basics.

Which PowerShell version are you using ? Do a

$PSVersionTable

Can you at least get the root into a variable ?

$test = dir vmstores:\

On which vSphere version are you running this ?

And I assume you are connected to a vCenter ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
johndavidd
Enthusiast
Enthusiast

Powershell Version 2.0

I can get the root into a variable using:

$test = dir vmstores:\

I am connected to a vCenter (5.0)

0 Kudos
LucD
Leadership
Leadership

Can you try this variation on your script ?

$report = @()
dir vmstores:\ -Recurse -Include *-??????.vmdk | %{
 
$report += $_ | Select Name,DatastoreFullPath
}
$report


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
johndavidd
Enthusiast
Enthusiast

Yes, that seems to work just fine.

:smileyconfused:

0 Kudos