VMware Cloud Community
kastek
Contributor
Contributor
Jump to solution

How to list delta files in all datastores

I've recently found the VI Toolkit and have learned a lot from these forums.

I'd like to be able to search the contents of all datastores for the existence of any delta files, indicating the presence of lingering snapshots...old or new.

I'd like to see the paths, filenames, sizes and dates of any delta files.

Can anyone point me in the right direction?

Thank you...Mike

Tags (3)
Reply
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

This is pretty easy with the VI Toolkit Community Extensions.

If you use that, you can run

get-datastore | get-tkedatastorefile | where { $_.Path -match "delta" }

to find these files.

The extensions require PowerShell 2 CTP2. If that's a non-starter for you for some reason the script code should at least tell you enough to get started.

View solution in original post

Reply
0 Kudos
25 Replies
admin
Immortal
Immortal
Jump to solution

This is pretty easy with the VI Toolkit Community Extensions.

If you use that, you can run

get-datastore | get-tkedatastorefile | where { $_.Path -match "delta" }

to find these files.

The extensions require PowerShell 2 CTP2. If that's a non-starter for you for some reason the script code should at least tell you enough to get started.

Reply
0 Kudos
kastek
Contributor
Contributor
Jump to solution

Wow...that was easy...thank you very much.

Is there an easy way to have the output not truncate, so I can see the whole Path and Modification fields?

Path Size Modification Datastore

[HNVMW30001SAN01... 16777216 1/14/2008 7:00:1... HNVMW30001SAN01

[HNVMW30001SAN01... 16777216 1/14/2008 7:00:1... HNVMW30001SAN01

Thank you...Mike

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

Either pipe the output into

format-list *

or you can pipe it into

select Path, Modification

.

kastek
Contributor
Contributor
Jump to solution

Perfect...thanks again...but...when I run the following commands separately from the Powershell command line they work fine...

-


Add-PSSnapin VMWare.VImAutomation.Core

"C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts\Initialize-VIToolkitEnvironment.ps1"

Add-Module "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\coreModule\viToolkitExtensions.psm1"

Connect-VIServer -Server 192.168.xxx.xxx -User xxx -Password xxx

Get-Datastore | get-tkedatastorefile | where { $_.Path -match "delta" } | format-list * > c:\deltachk.txt

-


...but when I run them inside a script using "PowerShell.exe c:\deltachk.ps1" I get the following errors...

-


Get-View : 10/10/2008 11:28:32 AM Get-View You are not currently connected to any servers. Please connect first using Connect-VIServer or one of its aliases.

At C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\coreModule\viToolkitExtensions.psm1:460 char:28

+ $datastoreView = get-view <<<< $ds.id

Get-View : The argument cannot be null or empty.

At C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\coreModule\viToolkitExtensions.psm1:461 char:31

+ $datastoreBrowser = get-view <<<< $datastoreView.browser

You cannot call a method on a null-valued expression.

At C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\coreModule\viToolkitExtensions.psm1:468 char:59

+ $task = $datastoreBrowser.SearchDatastoreSubFolders_Task <<<< ("[$name] /$subpath", $spec)

-


...what am I doing wrong???

Thank you...MIke

Message was edited by: kastek

Reply
0 Kudos
kastek
Contributor
Contributor
Jump to solution

Can anyone see what I'm doing wrong in thepost above?

Thank you...Mike

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The message says you are not connected.

So perhaps add a Connect-VIServer at the beginning of your c:\deltachk.ps1 script.


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

Reply
0 Kudos
Skark166
Contributor
Contributor
Jump to solution

I always use this to initialize the toolkit:

$vmsnap = Get-PSSnapin vmware* -ErrorAction SilentlyContinue
if ($vmsnap -eq $NULL) { Add-PSSnapIn -Name VMWare.VimAutomation.core }
Initialize-VIToolkitEnvironment.ps1

Skark166

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That loads the VITK snapin and defines some aliases and functions (in Initialize-VIToolkitEnvironment.ps1) but it doesn't do a Connect-VIServer.


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

Reply
0 Kudos
kastek
Contributor
Contributor
Jump to solution

Thanks LucD...but I do call the "Connect-VIServer" command already?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

To further analyse what exactly goes wrong it would perhaps be useful if you posted the script.


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

Reply
0 Kudos
kastek
Contributor
Contributor
Jump to solution

Script attached...

Reply
0 Kudos
Skark166
Contributor
Contributor
Jump to solution

I think you'd be ok if you ditched line 4.

Skark166

Reply
0 Kudos
kastek
Contributor
Contributor
Jump to solution

Line 4...you mean the one that adds the viToolkitExtensions.psm1?

If I don't have that the "get-tkedatastorefile" command is not recognized.

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

The problem may be that the connection is not actually succeeding.

Can you replace line 6 with just "get-datastore" and see if you get any output?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Add-Module is a cmdlet from PowerShell v2, and PowerShell 2 CTP2 is required for the VITK Community Extensions.

So that should be ok.

And I can't see anything wrong in the script.

Are you sure the Connect-VIServer is working ?

Do you see the "Name Port User" message in the output ?


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

Reply
0 Kudos
kastek
Contributor
Contributor
Jump to solution

Yes I do get output...and just to clarify...when I issue the commands one at a time inside powershell it works fine...just doesn't work via the script?

Reply
0 Kudos
kastek
Contributor
Contributor
Jump to solution

Yes I do see the "Name Port User" in the output

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

There is a scoping problem with the $defaultVIServer variable.

This is a workaround: in your script change:

Connect-VIServer -Server 192.168.xxx.xxx -User xxx -Password xxx

to

$server = Connect-VIServer -Server 192.168.xxx.xxx -User xxx -Password xxx
$global:defaultVIServer = $server

It seems there is something peculiar about script cmdlets that makes them run in a different context from other cmdlets. The way we populate and use $defaultVIServer is probably not helping.

Reply
0 Kudos
kastek
Contributor
Contributor
Jump to solution

Still not working...same error

Reply
0 Kudos