在powershell中运行引用UNC路径的cmd(Running a cmd in powershell referencing a UNC path)

编程入门 行业动态 更新时间:2024-10-26 01:30:40
在powershell中运行引用UNC路径的cmd(Running a cmd in powershell referencing a UNC path)

我正在创建一个PowerShell脚本来检查OU用户是否已针对已配置文件共享存档的用户进行检查,但我遇到了绊脚石。 我可以查询AD以获取每个OU及其主目录的用户列表,将所有详细信息转储到日志的文本文件中并基于后续查询。 获得这些详细信息后,我尝试运行dos命令(Enterprise Vault)Archivepoints.exe将变量传递给它。 该命令通常是:

Archivepoints.exe find \\fopserver045v\ouone_users$

当我尝试运行以下代码时出现错误。

$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.

起初我以为它错过了导致问题的UNC路径的第一个反斜杠,但我不再确定。

脚本和命令在EV服务器上运行,UNC浴缸实际上并没有进入服务器,它只是EV中的参考路径,因此它不是凭证问题。

如果可能的话,我还需要能够将输出记录到文件中。

代码应该是什么样的,我应该使用invoke-command还是Invoke-Expression?

谢谢

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. 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. Once I have these details I try to run a dos command, (Enterprise Vault) Archivepoints.exe passing variables to it. 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.

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.

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 ?

Thanks

最满意答案

不要使用Invoke-Item 。 应使用调用运算符( & )运行外部命令。 您可以使用splatting作为参数列表。

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

Don't use Invoke-Item. External commands should be run using the call operator (&). You can use splatting for the argument list.

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

更多推荐

本文发布于:2023-08-07 23:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466444.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   UNC   powershell   cmd   path

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!