2014-10-11 81 views
0

我正在將通過ShadowProtect捕獲的備份映像掛載到Explorer掛載點。我最初的測試是通過PowerShell中的測試文件查找驅動器上存在的文件。如果爲TRUE,我們可以假設備份映像已安裝並且「很好」。測試目錄是否可瀏覽

我的問題與SystemReserved分區有沒有文件,我可以測試的存在。在PowerShell(或NET?)中是否有任何函數可以簡單地測試目錄是否可以瀏覽(而不是查找某個文件?)。或者其他可以實現類似目的的想法?

謝謝!

注意:圖像是隻讀的。

+0

您能否檢查您是否可以列出目錄內容;即'Get-ChildItem \\ My \ Path \ ... \'? – JohnLBevan 2014-10-11 16:54:17

回答

1
$myPath = \\backupserver\share\folder\ 
$canRead = $true 
try { 
    Get-ChildItem $myPath -ErrorAction Stop | out-null 
} catch [System.Exception] { #could be more specific on type of error here, but I'm guessing most errors would suggest some issue equivelant to a read permissions issue. 
    $canRead = $false 
} 
if($canRead) { ":)" } else { ":(" }