I can get a list of my datastores with a get-datastore command, but for the life of me I cann figure out how to drill down into the folders and files below. I want to get a list of directories within each datastore and then the files within each folder. I'm a new Powershell scripter, so I'm sure I'm missing something simple. I also tried get-vmhoststorage, but (with a lot more effort) I get to the same data I get with get-datastore.
Thanks!
Tim
Hi Tim,
Check out the datastore provider, documented on page 21 of the VI Toolkit Administrator's Guide.
Brief rundown:
PS C:\> get-datastore Name FreeSpaceMB CapacityMB ---- ----------- ---------- storage1 18100 132864 33GB_shared 3040 68608 200GB_Shared 19252 204544 PS C:\> $datastore = get-datastore storage1 PS C:\> new-psdrive -location $datastore -name ds -psprovider VimDatastore -Root '\' Name Provider Root CurrentLocation ---- -------- ---- --------------- ds VimDatastore \Datastore\443@10.21.10.80\Datas... \ PS C:\> cd ds: PS ds:\> dir Datastore path: [storage1] LastWriteTime Type Length Name ------------- ---- ------ ---- 8/22/2008 4:28 AM Folder Harvey-test 8/20/2008 5:23 AM Folder DVM333 8/20/2008 5:23 AM Folder Nworks 10/22/2007 10:34 PM Folder Support 8/20/2008 5:23 AM Folder SupportVM 8/20/2008 5:23 AM Folder WinXPSP2-02 2/24/2008 2:01 PM Folder linux 8/20/2008 5:23 AM Folder SupportVM2 8/20/2008 5:23 AM Folder Lifecycle Manager 8/20/2008 5:23 AM Folder Windows 2003 VM 1 6/4/2008 11:57 PM Folder vm10 7/31/2008 1:05 AM Folder Win2k3 Template 8/20/2008 5:23 AM Folder openfiler-2.3-x86 8/20/2008 5:23 AM Folder nedko-clonetest 8/20/2008 5:23 AM Folder nedko-xptest 8/20/2008 5:23 AM Folder ε??α??στ? 8/20/2008 5:23 AM Folder VC VM 8/13/2008 4:54 AM FloppyImageFile 1474560 test.flp 7/24/2008 5:42 AM File 210892800 openfiler-2.3-x86.esx...
Hi Tim,
Check out the datastore provider, documented on page 21 of the VI Toolkit Administrator's Guide.
Brief rundown:
PS C:\> get-datastore Name FreeSpaceMB CapacityMB ---- ----------- ---------- storage1 18100 132864 33GB_shared 3040 68608 200GB_Shared 19252 204544 PS C:\> $datastore = get-datastore storage1 PS C:\> new-psdrive -location $datastore -name ds -psprovider VimDatastore -Root '\' Name Provider Root CurrentLocation ---- -------- ---- --------------- ds VimDatastore \Datastore\443@10.21.10.80\Datas... \ PS C:\> cd ds: PS ds:\> dir Datastore path: [storage1] LastWriteTime Type Length Name ------------- ---- ------ ---- 8/22/2008 4:28 AM Folder Harvey-test 8/20/2008 5:23 AM Folder DVM333 8/20/2008 5:23 AM Folder Nworks 10/22/2007 10:34 PM Folder Support 8/20/2008 5:23 AM Folder SupportVM 8/20/2008 5:23 AM Folder WinXPSP2-02 2/24/2008 2:01 PM Folder linux 8/20/2008 5:23 AM Folder SupportVM2 8/20/2008 5:23 AM Folder Lifecycle Manager 8/20/2008 5:23 AM Folder Windows 2003 VM 1 6/4/2008 11:57 PM Folder vm10 7/31/2008 1:05 AM Folder Win2k3 Template 8/20/2008 5:23 AM Folder openfiler-2.3-x86 8/20/2008 5:23 AM Folder nedko-clonetest 8/20/2008 5:23 AM Folder nedko-xptest 8/20/2008 5:23 AM Folder ε??α??στ? 8/20/2008 5:23 AM Folder VC VM 8/13/2008 4:54 AM FloppyImageFile 1474560 test.flp 7/24/2008 5:42 AM File 210892800 openfiler-2.3-x86.esx...
Ahhh... RTFM error! I didn't even realize there was one until now. Thanks!
Tim
Be forewarned that it's basically just for looks. You can traverse directories with 'cd', and you can get listings using 'dir' but that's about it at this point. Hopefully they'll enhance it in the future to allow for copy to/from and other file operations, and some capability to get at the VI SDK object.
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)