gpt4 book ai didi

powershell - 如何使用凭据测试写入文件共享路径?

转载 作者:行者123 更新时间:2023-12-04 09:10:59 25 4
gpt4 key购买 nike

我有一个数组 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com