Powershell: Saving file to root

僤鯓⒐⒋嵵緔 提交于 2020-01-16 11:49:13

问题


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?

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


回答1:


Basicly the path to save on a root is:

\\servername\c$\myfile.xml

This is the path to save in the c:\ root folder of a remote machine. You need local administrator credentials of the server.




回答2:


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"
}


来源:https://stackoverflow.com/questions/10085418/powershell-saving-file-to-root

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!