gpt4 book ai didi

powershell - 我需要更改一些 “favorites”链接中的URL

转载 作者:行者123 更新时间:2023-12-02 23:47:22 25 4
gpt4 key购买 nike

我们正在5个Webshare网站上更改URL,以便它们仅响应HTTPS和FQDN请求。
我们很多用户的收藏夹中都有“内部”链接,当我们更改URL时,这些链接会中断。

我需要一种方法来打开每个“收藏夹”,看看是否有任何链接指向旧的URL,然后将其更改为新的URL。

这就是我想要做的(没有错误出现,但是链接未修改):

    # Set folder variable
$folder = $env:HOMEPATH + '\' + 'favorites' #'

# Backup the folder
Copy-Item $folder $env:homepath\favorites1 -recurse

# set the stringtofind variables
$stringToFind1 = "http://wss1/"
$stringToFind2 = "http://iwds/"
$stringToFind3 = "http://webshare/"
$stringToFind4 = "http://mysites/"
$stringToFind5 = "http://eforms/"

# Set the stringtoplace variables
$stringToPlace1 = "https://wss1.FQDN.com"
$stringToPlace2 = "https://iwds.FQDN.com"
$stringToPlace3 = "https://webshare.FQDN.com"
$stringToPlace4 = "https://mysites.FQDN.com"
$stringToPlace5 = "https://eforms.FQDN.com"

# Execute the content changes
gci $folder\*.url -recurse | foreach-object { (Get-Content $_) | ForEach-Object { $_ -replace $stringToFind1, $stringToPlace1 } | Set-Content $_ }
gci $folder\*.url -recurse | foreach-object { (Get-Content $_) | ForEach-Object { $_ -replace $stringToFind2, $stringToPlace2 } | Set-Content $_ }
gci $folder\*.url -recurse | foreach-object { (Get-Content $_) | ForEach-Object { $_ -replace $stringToFind3, $stringToPlace3 } | Set-Content $_ }
gci $folder\*.url -recurse | foreach-object { (Get-Content $_) | ForEach-Object { $_ -replace $stringToFind4, $stringToPlace4 } | Set-Content $_ }
gci $folder\*.url -recurse | foreach-object { (Get-Content $_) | ForEach-Object { $_ -replace $stringToFind5, $stringToPlace5 } | Set-Content $_ }

最佳答案

您可以使用COM来操作快捷方式文件。使用 CreateShortcut method Shell class读取快捷方式文件:

$shell = New-Object -ComObject 'WScript.Shell';
$shortcut = $shell.CreateShortcut($shortcutPath);

然后,您可以阅读和修改 TargetPath property,并使用 Save method将更改提交到快捷方式文件:
$oldTargetPath = $shortcut.TargetPath;
Write-Host "Shortcut currently points to $oldTargetPath";
$shortcut.TargetPath = $newTargetPath;
$shortcut.Save();

关于powershell - 我需要更改一些 “favorites”链接中的URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16366831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com