3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

powershellでショートカットのリンク先変更

Last updated at Posted at 2017-10-04

フォルダの変更になってますが、
ファイルサーバ以降などの時にも使えそうな気がしますが......

$wsh=New-Object -ComObject wscript.shell
cd c:\Users\user\Desktop

サブフォルダも検索
$fnames=dir -Recurse -Include *.lnk

foreach($fname in $fnames){
$sht=$wsh.createshortcut($fname)
$fnamefull=$sht.fullname
$link_name=$sht.targetpath

リンク先を変更する
$str=$link_name.split("")
$str.length

if($str[1]="Users"){
$str[1]="dell"
$new_path=$str -join ""
$sht=$wsh.createshortcut($fnamefull)
$sht.targetpath=$new_path
$sht.save()
}else{
}
}

3
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?