Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Networking 如何在Powershell中隐藏网络使用的输出_Networking_Powershell_Output_Net Use - Fatal编程技术网

Networking 如何在Powershell中隐藏网络使用的输出

Networking 如何在Powershell中隐藏网络使用的输出,networking,powershell,output,net-use,Networking,Powershell,Output,Net Use,我正在使用此Powershell脚本连接网络路径: $usrLogin = [Environment]::UserName + "@mydomain.net" $cred = Get-Credential $usrLogin $networkCred = $cred.GetNetworkCredential() $usercred = $networkCred.UserName + '@' + $networkCred.Domain $extractSource = "\\srv01\d$\"

我正在使用此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
我决定使用“netuse”,因为稍后我将在脚本中打开一个直接打开网络路径的文件对话框

$openFileDialog1 = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog1.initialDirectory = "\\srv01\d$\"
现在我的问题是:

如何隐藏“net use”命令的输出?我试过了,但没用:

net use $extractSource $networkCred.Password /USER:$usercred | out-null

当我运行它时,上面的行工作(管道到
输出null
)。如果仍然不适合您,请尝试以下操作:

(net use $extractSource $networkCred.Password /USER:$usercred) | out-null 
或者存储在$null中,如下所示:

$null = net use $extractSource $networkCred.Password /USER:$usercred 

当我运行它时,上面的行工作(管道到
输出null
)。如果仍然不适合您,请尝试以下操作:

(net use $extractSource $networkCred.Password /USER:$usercred) | out-null 
或者存储在$null中,如下所示:

$null = net use $extractSource $networkCred.Password /USER:$usercred 

您可以将错误流重定向到null:

net use $extractSource $networkCred.Password /USER:$usercred 2>null
或者使用2>&1将错误流重定向到标准输出流,并将两者都重定向到null:

net use $extractSource $networkCred.Password /USER:$usercred 2>&1>null

您可以将错误流重定向到null:

net use $extractSource $networkCred.Password /USER:$usercred 2>null
或者使用2>&1将错误流重定向到标准输出流,并将两者都重定向到null:

net use $extractSource $networkCred.Password /USER:$usercred 2>&1>null

不幸的是,这两种选择都不适合我。。。它仅隐藏来自“net use”命令的成功消息,而不隐藏错误警告。例如,当我运行该命令两次时,即使我将其导出null:net.exe,仍然会出现这样的错误:系统错误1219。在第133行char:16+$null=net这是您应该在问题中指定的内容。要处理错误输出,请参阅Shay的答案。对于这个不确定的问题,很抱歉。。。无论如何谢谢你!不幸的是,这两种选择都不适合我。。。它仅隐藏来自“net use”命令的成功消息,而不隐藏错误警告。例如,当我运行该命令两次时,即使我将其导出null:net.exe,仍然会出现这样的错误:系统错误1219。在第133行char:16+$null=net这是您应该在问题中指定的内容。要处理错误输出,请参阅Shay的答案。对于这个不确定的问题,很抱歉。。。无论如何谢谢你!非常感谢,这就是我要找的!我一直认为我需要使用一个“>”:-)的管道安装,你能解释一下2>&1>null在做什么吗?重定向号码如何处理错误?很抱歉回复太晚。这些数字表示控制台流,2表示错误流。你可以在about_Redirection help topicThanks中找到更多信息,这就是我要找的!我一直认为我需要使用一个“>”:-)的管道安装,你能解释一下2>&1>null在做什么吗?重定向号码如何处理错误?很抱歉回复太晚。这些数字表示控制台流,2表示错误流。您可以在关于重定向帮助主题中找到更多信息