我有一个数组 Credential
对象,我想测试这些凭据是否具有将文件写入文件共享的权限。
我要做类似的事情
$myPath = "\\path\to\my\share\test.txt"
foreach ($cred in $credentialList)
{
"Testing" | Out-File -FilePath $myPath -Credential $cred
}
但后来我发现
Out-File
不带Credential
作为参数。解决这个问题的最佳方法是什么?
最佳答案
您可以使用 New-PSDrive:
$myPath = "\\path\to\my\share"
foreach ($cred in $credentialList)
{
New-PSDrive Test -PSProvider FileSystem -Root $myPath -Credential $Cred
"Testing" | Out-File -FilePath Test:\test.txt
Remove-PSDrive Test
}
关于powershell - 如何使用凭据测试写入文件共享路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21335134/