Powershell:将文件保存到根目录 [英] Powershell: Saving file to root

查看:88
本文介绍了Powershell:将文件保存到根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个 powershell 文件,该文件将收集信息并将其保存到 XML 文件中.该脚本将在多台计算机上运行,​​因此我想将它们全部保存到根路径中.问题是,如何将 XML 文件保存到计算机上的根目录?

I'm running a powershell file which are going to gather information an save it to an XML-file. This script will run on several computers, and so I want to save them all to a rootpath. The question is, how do I save an XML-file to root on a computer?

要指定:脚本将始终在本地计算机上运行,​​因此我需要将 xml 文件保存到本地路径..

To specify: The script will always run on a local computer, hence I need to save the xml file to a local path..

推荐答案

如果我理解正确的话..如果您有权访问相关计算机的根驱动器...这会将每个以计算机名称命名的 xml 文件保存在每台计算机的 C 驱动器中.

If I understood correctly.. If you have access to the root drive of the computers in question... this will save each xml file, named after its computer name, in the C drive of each computer.

"comp1","comp2","comp3" | Foreach-Object {
   $xml = ....
   $xml | Out-File -Path "\\$_\c$\$_.xml"
}

这篇关于Powershell:将文件保存到根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆