获取计算机名称并根据结果重命名文件

发布于 2025-01-30 16:08:02 字数 402 浏览 1 评论 0原文

我想在启动上运行一个Power Shell脚本,该脚本将查询本地主机名并通过插入结果重命名本地文件。

例如,使用以下内容获取主机名

$(Get-WmiObject Win32_Computersystem).name

,并将结果插入命名和位于下面的文件中,

C:\output\file-from-`Insert hostname`.txt

使用get-wmiObject将其命名为我粘贴的现有文件的结果和。

任何帮助都会很棒。

:-)

I'd like to run a Power shell script on start up that will query the local hostname and rename a local file by inserting the result.

For example, get hostname using something like:

$(Get-WmiObject Win32_Computersystem).name

..and insert the result into a file named and located as below,

C:\output\file-from-`Insert hostname`.txt

Its using the result of the Get-WmiObject to rename the existing file that I'm stuck with.

Any help would be great.

:-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

能否归途做我良人 2025-02-06 16:08:02

这应该解决问题。

Rename-Item -Path "C:\output\file-from-Insert hostname.txt" -NewName "C:\output\file-from-$($env:COMPUTERNAME).txt"

This should do the trick.

Rename-Item -Path "C:\output\file-from-Insert hostname.txt" -NewName "C:\output\file-from-$($env:COMPUTERNAME).txt"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文