PowerCLI

 View Only
  • 1.  Script to check for Delta Files

    Posted Jul 23, 2012 03:37 PM

    I'm looking for a script that can scan each host and check for a 000002 or higher delta file, and doesn't rely on the snapshot manager.

    Does anyone have something like this?

    Thanks



  • 2.  RE: Script to check for Delta Files

    Posted Jul 23, 2012 03:59 PM

    Take a look at the following thread: http://communities.vmware.com/message/2080437#2080437.

    Regards, Robert



  • 3.  RE: Script to check for Delta Files

    Posted Jul 23, 2012 05:15 PM

    Thanks for the response. I checked out that script, but it didn't get me where I need to be.

    There is a vm that I know has some delta files on it. I can see it when I browse the datastore, however this script didn't pick them up (maybe because they're not in use anymore).

    My goal is to find any stale snapshots on any datastores with a delta 000002 or higher, whether in use or not in use, so I can get them cleaned up.

    Thank you again!



  • 4.  RE: Script to check for Delta Files

    Posted Jul 23, 2012 05:42 PM

    You can try something like:

    Get-datastore |
    ForEach-Object {Get-ChildItem $_.DatastoreBrowserPath -Recurse} |
    Where-Object {$_.Name -like "*-0*.vmdk" -and $_.Name -notlike "*-000000.vmdk"-and $_.name -notlike "*-000001.vmdk"}
    
    



  • 5.  RE: Script to check for Delta Files

    Posted Jul 23, 2012 06:07 PM

    Thanks again for the response. I'm trying our your scripts, but the 000000 and 000001 are still showing.

    Also, how can I prevent the name column from cutting of in the end? I can't see the full file name.

    Thank you!



  • 6.  RE: Script to check for Delta Files

    Posted Jul 23, 2012 06:18 PM

    You probably still see the *-000000-delta.vmdk files. The next improved script version filters the delta files also. To show the full name I select the name property only:

    Get-datastore |
    ForEach-Object {Get-ChildItem $_.DatastoreBrowserPath -Recurse} |
    Where-Object {$_.Name -like "*-0*.vmdk" -and $_.Name -notlike "*-000000.vmdk" -and $_.Name -notlike "*-000001.vmdk" -and $_.Name -notlike "*-000000-delta.vmdk" -and $_.Name -notlike "*-000001-delta.vmdk"} |
    Select-Object -Property Name
    
    



  • 7.  RE: Script to check for Delta Files

    Posted Jul 23, 2012 06:22 PM

    Try this RegEx based filter, it avoids this long list of -and operators

    $regex = [regex]"\[\w*\]\s\w*/\w*-(?!00000[01])\d*\.vmdk"
    
    Get-datastore
    | %{   Get-ChildItem $_.DatastoreBrowserPath -Recurse |
     
    where {$_.DatastoreFullPath -match $regex} | Select DatastoreFullPath
    }


  • 8.  RE: Script to check for Delta Files

    Posted Jul 23, 2012 08:40 PM

    I modified Luc's script slightly to also display VM's with e.g. hyphens and blanks in their names (or in the datastore name) and to display the whole name in case of long file and folder names.

    $regex = [regex]".+-[0-9]{5}[2-9][\-\w]{0,6}\.vmdk"

    Get-datastore | %{
      Get-ChildItem $_.DatastoreBrowserPath -Recurse |
      where {$_.DatastoreFullPath -match $regex} | Select DatastoreFullPath |
      ft -Property * -Autosize | Out-String -Width 512
    }

    In case you only want to display either the header or the delta file name , replace the regex with:

    $regex = [regex]".+-[0-9]{5}[2-9]\.vmdk"

    or

    $regex = [regex]".+-[0-9]{5}[2-9]-delta\.vmdk"

    André



  • 9.  RE: Script to check for Delta Files

    Posted Jul 23, 2012 09:00 PM

    Nice one, but aren't you excluding also snapshots the end in 000010, 000011, 000020.... ?

    That's why I used the negative look ahead.



  • 10.  RE: Script to check for Delta Files

    Posted Jul 23, 2012 09:13 PM

    You are right, I just saw this too and modified the regex to

    $regex = [regex]".+-(?!000001)\d{6}-delta\.vmdk"

    André