kcvman
Contributor
Contributor

Extending the getorphanedvmdk.ps1 script

First off, kudos for a great script go to MorDrakka. Even though it does show snapshots as well as orphaned, which requires some manual sorting to verify what is what, it's still very helpful.

I need to add the size of the found file to this script, but have been unsucessful so far. Can anyone assist?

Thanks.

Tags (3)
0 Kudos
10 Replies
marco_shaw
Contributor
Contributor

There are several ways this can be achieved. Here's one:

To this section of the .ps1 script:

...

$file.Name = $fileResult.Path

$strFilename = $file.Name

...

Add this line:

$strLength = $fileResult.Length

To this section of the .ps1 script:

...

$strOutput = $strDatastoreName + " Orphaned VMDK Found: " + $strFilename

$strOutput | Out-File $Outputfile -width 150 -Append

...

Change the above 2 lines to:

$strOutput = $strDatastoreName + " Orphaned VMDK Found: " + $strFilename + " " + $strLength

$strOutput | Out-File $Outputfile -width 150 -Append

Give that a try...

You may want to add some extra logic to be able to get a better output like X MB or Y GB?

0 Kudos
kcvman
Contributor
Contributor

Marco -

No joy on the additions. It returns a blank space for $strLength. Here's what my script looks like aftr making your corrections. Any ideas?

$file = "" | select Name, FullPath

$file.Name = $fileResult.Path

$strFilename = $file.Name

$strLength = $fileResult.Length

IF ($strFilename)

{

IF ($strFilename.Contains(".vmdk"))

{

IF (!$strFilename.Contains("-flat.vmdk"))

{

IF (!$strFilename.Contains("delta.vmdk"))

{

$strCheckfile = ""$file.Name""

IF ($arrUsedDisks -Like $strCheckfile){}

ELSE

{

$strOutput = $strDatastoreName + "," +$strFilename ","$strLength

$strOutput | Out-File $Outputfile -width 150 -Append

0 Kudos
marco_shaw
Contributor
Contributor

Where is that script again? I can't find it anymore...

Marco

0 Kudos
kcvman
Contributor
Contributor

Attached are your original and my modified.

0 Kudos
marco_shaw
Contributor
Contributor

After this line in the original version:

$file.Name = $fileResult.Path

Add this:

$fileResult|get-member

I'd like to see the output from that part...

If you can't I'll try to fire up a VI connection tomorrow...

Marco

0 Kudos
kcvman
Contributor
Contributor

Attached is the output from adding the line -

$fileResult|get-member

to your original script. I also added " | out-file c:\member.txt -append" to capture the output instead of screen prints.

0 Kudos
marco_shaw
Contributor
Contributor

I'm so sorry... I'm just coming back to this forum now. Did you still need help?

0 Kudos
joni2009
Contributor
Contributor

Hello.

Thank you for you script. Its a greatfull tool to find orphaned vmdks.

I'm using it in ESX 3.0 with good results, but it doesn't work in 3.5.

It reports the following error:

"Referencia a objeto no establecida como instancia de un objeto"

translated my be like this

"Reference to an object not stablished as an object instance."

in the line:

$arrUsedDisks = Get-VM | Get-HardDisk | %{$_.filename}

Could you help me?

If you need any other information do not hesitate in contacting me.

Thank you in advance,

kind regards, joni.

0 Kudos
sp93
Contributor
Contributor

Did you find a resolution to this. I would love to run this on my VI 2.5 ESX 3.5 servers?

0 Kudos
LucD
Leadership
Leadership

See my version of the script in


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

0 Kudos