如何使用凭据测试写入文件共享路径? [英] How to test writing to a file share path using credential?
本文介绍了如何使用凭据测试写入文件共享路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组 Credential
对象,我想测试这些凭据是否具有将文件写入文件共享的权限.
I have an array of Credential
objects and I would like to test that these credentials have permissions to write a file to a file share.
我想做类似的事情
$myPath = "\\path\to\my\share\test.txt"
foreach ($cred in $credentialList)
{
"Testing" | Out-File -FilePath $myPath -Credential $cred
}
但后来我发现 Out-File
没有将 Credential
作为参数.解决此问题的最佳方法是什么?
but then I discovered that Out-File
doesn't take Credential
as a parameter. What's the best way to solve this?
推荐答案
您可以使用 New-PSDrive:
You can use 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
}
这篇关于如何使用凭据测试写入文件共享路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文