我们正在更改5个网站共享网站上的网址,以便它们仅响应HTTPS和FQDN请求。 很多我们的用户在我们的收藏夹中有“内部”链接,当我们更改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 $_ }
非常方便;只是为了明确说明:这种方法可以读取/更新/创建常规快捷方式文件('* .lnk')以及URL快捷方式文件('* .url')(收藏夹)。 – mklement0 2017-02-17 21:28:43