Created
October 1, 2015 08:02
-
-
Save tomoko523/f8d63327b81ff1fb5992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# フォルダ内のショートカットを検索し、ショートカットの内容を変更する。 | |
clear-host | |
# 値を設定 | |
$folder = "…" # 検索対象フォルダ | |
write-host "対象フォルダ:" $folder | |
$search = "…" # 置換前 | |
$replace = "…" #置換後 | |
$filter = "…" + "*" #前方一致で検索 | |
"ショートカットを検索中。しばらくお待ちください ..." | |
$shortcuts = get-childitem -path $folder -recurse -include *.lnk | |
$count = $shortcuts.length | |
if ($count -eq 0) { | |
"ショートカットがみつかりませんでした。", "終了します。" | |
exit 9 | |
} | |
$shell = new-object -comobject WScript.Shell | |
write-host $count "件のショートカットがみつかりました。" | |
$shortcuts | foreach-object { | |
echo $_.fullname | |
$wsc = $shell.CreateShortcut($_.fullname) | |
# ショートカット一覧が欲しいだけの場合はここまで | |
# echo $wsc.TargetPath | |
# パス変換 | |
if ($wsc.TargetPath -ilike $filter) { | |
echo "変更前" $wsc.TargetPath | |
$wsc.TargetPath = $wsc.TargetPath.Replace($search, $replace) | |
$wsc.Save() | |
echo "変更後" $wsc.TargetPath | |
} | |
#elseif ($wsc.TargetPath -ilike "…*"){ | |
# | |
# # 他に何か置換したいとき | |
# | |
# } | |
echo "未変更" $wsc.TargetPath | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment