|
# http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/26/use-powershell-to-work-with-windows-explorer.aspx |
|
$o = New-Object -com Shell.Application |
|
$folder = $o.NameSpace(0x11) |
|
|
|
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb774096(v=vs.85).aspx |
|
# ShellSpecialFolderConstants.ssfDRIVES == 0x11 |
|
|
|
$items = $folder.Items() |
|
for ($i= 0; $i -lt $items.Count; $i++) { |
|
write-output ([string]$i + ": " + $items.Item($i).Name) |
|
} |
|
$choice = Read-Host "Make your choice" |
|
|
|
$android = $items.Item([int]$choice) |
|
$root = $android.GetFolder() |
|
|
|
# FolderItem versus FolderItems |
|
|
|
$maxdepth = Read-Host "Max depth" |
|
|
|
Function Write-Items($item, $depth, $maxdepth) { |
|
if ($depth -ge $maxdepth) { |
|
return; |
|
} |
|
$indent = "" |
|
for ($i = 0; $i -lt $depth; $i++) { |
|
$indent += " "; |
|
} |
|
#write-output ($indent + "Name: " + $item.name) |
|
if ($item.Title) { |
|
$hash = @{ |
|
Name = $item.Title |
|
Size = $null #$item.ParentFolder.GetDetailsOf($item, 2) |
|
Modified = $null #$item.ParentFolder.GetDetailsOf($item, 3) |
|
Parent = $item.ParentFolder.Title |
|
Level = $depth |
|
} |
|
$Object = New-Object PSObject -Property $hash |
|
write-output $object |
|
} else { |
|
$hash = @{ |
|
Name = $item.Name |
|
Size = $item.Parent.GetDetailsOf($item, 2) |
|
Modified = $item.Parent.GetDetailsOf($item, 3) |
|
Parent = $item.Parent.Title |
|
Level = $depth |
|
} |
|
$Object = New-Object PSObject -Property $hash |
|
Write-Output $object |
|
} |
|
if ($item.Count -gt 0) { |
|
# $item is a folder with its own items |
|
for ($i = 0; $i -lt $item.Count) { |
|
$item2 = $item.item($i) |
|
Write-Items $item2 $depth+1 $maxdepth |
|
} |
|
|
|
} |
|
else { |
|
if ($item.Items) { |
|
$items = $item.Items() |
|
if ($items.Count -gt 0) { |
|
foreach ($i in $items) { |
|
if ($i.IsFolder) { |
|
$folder = $i.GetFolder() |
|
Write-Items $folder ($depth+1) $maxdepth |
|
} |
|
else { |
|
Write-Items $i ($depth+1) $maxdepth |
|
} |
|
} |
|
} |
|
} |
|
else { |
|
# .Count == 0 and no Items present |
|
# we don't need to do anything further here |
|
} |
|
} |
|
} |
|
|
|
Write-Items $root 0 $maxdepth | Out-GridView |
|
|
I think you need to change
$android.GetFolder()
to
$android.GetFolder
It's a property, not a method. (though its name implies otherwise)