简体   繁体   English

在Powershell中运行cmd,引用UNC路径

[英]Running a cmd in powershell referencing a UNC path

I'm in the process of creating a powershell script to check OU users against users already configured for file share archiving but I've hit a stumbling block. 我正在创建一个Powershell脚本,以对照已配置文件共享归档的用户来检查OU用户,但遇到了一个绊脚石。 I can query AD to get a list of users per OU and their home directories, dumping all of the details out to text files for logs and basing subsequent queries on. 我可以查询AD以获取每个OU及其主目录的用户列表,将所有详细信息转储到文本文件中以进行日志记录,然后进行后续查询。 Once I have these details I try to run a dos command, (Enterprise Vault) Archivepoints.exe passing variables to it. 获得这些详细信息后,我尝试运行一个dos命令,(Enterprise Vault)Archivepoints.exe将变量传递给它。 The command would usually be : 该命令通常为:

Archivepoints.exe find \\fopserver045v\ouone_users$

When I try to run the following code I get an error. 当我尝试运行以下代码时,出现错误。

$app="D:\Enterprise Vault\ArchivePoints.exe"
$EVArg = "find"
$VolLine = "\\fopserver045v\ouone_users_r$"
Invoke-Item "$app $EVArg $VolLine"

Invoke-Item : Cannot find path 'D:\Enterprise Vault\ArchivePoints.exe find \fopserver045v\ouone_users_r$' because it does not exist.

At first I thought it was missing the first backslash of the UNC path that was causing the issue but I'm no longer sure. 起初,我认为它缺少导致问题的UNC路径的第一个反斜杠,但我不确定。

The script and command run on the EV server and the UNC bath doesn't actually go to the server, it's only a reference path within EV so it's not a credentials issue. 脚本和命令在EV服务器上运行,而UNC浴实际上并没有到达服务器,它只是EV中的参考路径,因此不是凭据问题。

I need to be able to log the output to file too if possible. 如果可能,我还需要能够将输出记录到文件中。

What should the code look like and should I be using invoke-command or Invoke-Expression instead ? 代码应该是什么样子?我应该改用invoke-command或Invoke-Expression吗?

Thanks 谢谢

Don't use Invoke-Item . 不要使用Invoke-Item External commands should be run using the call operator ( & ). 外部命令应使用调用运算符( & )运行。 You can use splatting for the argument list. 您可以对参数列表使用splatting

$app="D:\Enterprise Vault\ArchivePoints.exe"
$arguments = "find", "\\fopserver045v\ouone_users_r$"

& $app @arguments

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM