使用 PowerShell 更改 rdp 文件的内容 [英] Change the contents of a rdp-file with PowerShell
问题描述
我有一个目录 C:\RDP LINKS\,您可以在其中找到一大堆带有 rdp 快捷方式的文件夹.
I have a directory C:\RDP LINKS\ in which you find a whole bunch of folders with rdp shortcuts.
问题是,所有快捷方式中的默认名称最近都已更改(首先是 administrator@testdomain.local,现在是 administrator@test2domain.local.
The problem is, is that the default name in all of the shortcuts has been changed recently (first it was administrator@testdomain.local and now it's administrator@test2domain.local.
我想用 Powershell 更改 rdp 链接的内容.
i want to change the contents of the rdp links with Powershell.
如果用记事本打开rdp快捷方式,可以看到属性和默认用户名:
If you open the rdp shortcut with notepad, you can see the properties and the default user name:
我试过这个脚本:
$configFiles = Get-ChildItem "C:\RDP LINKS\" *.rdp -rec
foreach ($file in $configFiles)
{
(Get-Content $file.PSPath) |
Foreach-Object { $_ -replace "administrator@testdomain.local", "administrator@test2domain.local" } |
Set-Content $file.PSPath
}
脚本运行但名称没有改变.我究竟做错了什么?
The script runs but the name doesn't change. What am i doing wrong?
推荐答案
试试这个(使用 fullname 属性而不是 pspath):
try this instead (use fullname property instead of pspath) :
ls "c:\rdp links\*.rdp" -recurse | %{
(gc $_ ) -replace "administrator@testdomain.local", "administrator@test2domain.local" |
set-content $_.FullName -force
}
这篇关于使用 PowerShell 更改 rdp 文件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!