我正在使用这个 Powershell 脚本来连接网络路径:
$usrLogin = [Environment]::UserName + "@mydomain.net"
$cred = Get-Credential $usrLogin
$networkCred = $cred.GetNetworkCredential()
$usercred = $networkCred.UserName + '@' + $networkCred.Domain
$extractSource = "\\srv01\d$\"
net use $extractSource $networkCred.Password /USER:$usercred
我决定使用“net use”,因为稍后我将在脚本中打开一个直接打开网络路径的 FileDialog。
$openFileDialog1 = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog1.initialDirectory = "\\srv01\d$\"
现在我的问题:
如何隐藏“net use”命令的输出?我试过了,但没有用:
net use $extractSource $networkCred.Password /USER:$usercred | out-null