PowerCLI

 View Only
  • 1.  Script to find .ISO files in all of my datastores ?

    Posted Sep 12, 2011 01:23 AM

    Hi People,

    Can anyone please assist me in finding any .ISO files spread across my datastore with powershell script for both local datastore and SAN ?

    Thanks,

    AWT



  • 2.  RE: Script to find .ISO files in all of my datastores ?

    Posted Sep 12, 2011 01:40 AM

    Hello, AlbertWT-

    That is pretty straightfoward, thanks to the PSDrive "vmstores:\" that gets created in your PowerCLI session (specifically, when the VMware.VimAutomation.Core PSSnapin gets added to the session).  This PSDrive is created using the VimDatastore provider, and provides access to all of the datastores in all of the VIServers to which you are connected via Connect-VIServer.

    So, you can use a "dir" (alias for Get-ChildItem) to find the ISOs that you desire:

    dir vmstores:\ -Recurse -Include *iso | ft -a

    There are other ways to search datastores, but this should suit the need you mentioned.  How does that do for you?



  • 3.  RE: Script to find .ISO files in all of my datastores ?

    Posted Sep 12, 2011 01:55 AM

    Hi Matt,

    It doesn't show up anything ?

    I'm using PowerGUI Script Editor with the following configurations:

    PS Microsoft.PowerShell.Core\FileSystem::\\FileServer01\homedir\Albert> Get-PowerCLIVersion | ft -AutoSize
    Major Minor  Build Revision Copyright                          Company      UserFriendlyVersion                         SnapinVersions                              
    ----- -----  ----- -------- ---------                          -------      -------------------                         --------------                              
        4     1 332441        0 Copyright © VMware, Inc. 1998-2010 VMware, Inc. VMware vSphere PowerCLI 4.1 U1 build 332441 {VMWare vSphere PowerCLI 4.1 U1 build 332441}
    PS Microsoft.PowerShell.Core\FileSystem::\\FIleServer01\homedir\Albert> Get-PowerCLIConfiguration | ft -AutoSize
    Proxy Policy   Default Server Mode
    ------------   -------------------
    UseSystemProxy Multiple          
    PS Microsoft.PowerShell.Core\FileSystem::\\FileServer01\homedir\Albert> Get-PSProvider | ft -AutoSize
    Name         Capabilities                Drives            
    ----         ------------                ------            
    WSMan        Credentials                 {WSMan}           
    Alias        ShouldProcess               {Alias}           
    Environment  ShouldProcess               {Env}             
    FileSystem   Filter, ShouldProcess       {C, D, G, H...}   
    Function     ShouldProcess               {Function}        
    Registry     ShouldProcess, Transactions {HKLM, HKCU}      
    Variable     ShouldProcess               {Variable}        
    Certificate  ShouldProcess               {cert}            
    VimDatastore ShouldProcess               {vmstores, vmstore}
    VimInventory Filter                      {vis, vi}         
    PS Microsoft.PowerShell.Core\FileSystem::\\FileServer01\homedir\Albert> Get-PSSnapin | ft -AutoSize
    Name                                             PSVersion Description                                                                                                            
    ----                                             --------- -----------                                                                                                            
    Microsoft.PowerShell.Diagnostics                 2.0       This Windows PowerShell snap-in contains Windows Eventing and Performance Counter cmdlets.                             
    Microsoft.WSMan.Management                       2.0       This Windows PowerShell snap-in contains cmdlets (such as Get-WSManInstance and Set-WSManInstance) that are used by t...
    Microsoft.PowerShell.Core                        2.0       This Windows PowerShell snap-in contains cmdlets used to manage components of Windows PowerShell.                      
    Microsoft.PowerShell.Utility                     2.0       This Windows PowerShell snap-in contains utility Cmdlets used to manipulate data.                                      
    Microsoft.PowerShell.Host                        2.0       This Windows PowerShell snap-in contains cmdlets (such as Start-Transcript and Stop-Transcript) that are provided for...
    Microsoft.PowerShell.Management                  2.0       This Windows PowerShell snap-in contains management cmdlets used to manage Windows components.                         
    Microsoft.PowerShell.Security                    2.0       This Windows PowerShell snap-in contains cmdlets to manage Windows PowerShell security.                                
    Quest.ActiveRoles.ADManagement                   1.0       This Windows PowerShell snap-in contains cmdlets to manage Active Directory and Quest ActiveRoles Server.              
    VMware.VimAutomation.Core                        2.0       This Windows PowerShell snap-in contains Windows PowerShell cmdlets for managing vSphere.                              
    Microsoft.Exchange.Management.PowerShell.Admin   1.0       Admin Tasks for the Exchange Server                                                                                    
    Microsoft.Exchange.Management.Powershell.Support 1.0       Support Tasks for the Exchange Server                                                                                  

    I can use any other PS script in this forum but somehow even the simple "dir vmstores:\" command not working either ?



  • 4.  RE: Script to find .ISO files in all of my datastores ?
    Best Answer

    Posted Sep 12, 2011 06:04 AM

    The Format-Table -AutoSize cmdlet only shows output on screen when all objects are received.

    It can take very long before you see anything on screen due to the size of your datastores.

    Try it this way

    dir vmstores:\ -Recurse -Include *.iso | Select Name,FolderPath


  • 5.  RE: Script to find .ISO files in all of my datastores ?

    Posted Sep 12, 2011 07:13 AM

    Yes it works without the ft -autosize.

    Thanks to all who reply to my thread.

    Cheers,

    AWT



  • 6.  RE: Script to find .ISO files in all of my datastores ?

    Posted Sep 24, 2014 03:30 PM

    Just wanted to say thanks for the powercli snippet! Really comes in handy