個人的には、この .net コードを使用して、共有またはローカル パスにアクセスする例外をキャッチします。
このタイプをpowershellに追加します
add-type @"
using System;
using System.IO;
public class CheckFolderAccess {
public static string HasAccessToWrite(string path)
{
try
{
using (FileStream fs = File.Create(Path.Combine(path, "Testing.txt"), 1, FileOptions.DeleteOnClose))
{ }
return "Allowed";
}
catch (Exception e)
{
return e.Message;
}
}
}
"@
次のように使用します。
> [checkfolderaccess]::HasAccessToWrite("\\server\c$\system volume information")
Access to path '\\server\c$\system volume information\Testing.txt' denied.
> [checkfolderaccess]::HasAccessToWrite("\\nonexistingserver\nonexistingpath")
Path not found.