Created
September 4, 2017 03:48
-
-
Save hapo31/7f91dfe801585efddcc23126ac68212c to your computer and use it in GitHub Desktop.
シンボリックリンクを作成するPowerShellスクリプト
This file contains hidden or 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
| $Mode = Read-Host -Prompt "作成するシンボリックリンクの種類を選択:[0]ファイル [1]ディレクトリ" | |
| [void][System.Reflection.Assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089") | |
| if ($Mode -eq 0) { | |
| $dialog = New-Object System.Windows.Forms.OpenFileDialog | |
| $dialog.Filter = "すべてのファイル(*.*)|*.*" | |
| $dialog.Title = "リンクする先のファイルを選択" | |
| $dialog.InitialDirectory = "C:/" | |
| if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { | |
| $target = $dialog.FileName | |
| } | |
| else { | |
| Write-Output("キャンセルされました。処理を中断します。") | |
| exit | |
| } | |
| } | |
| else { | |
| $dialog = New-Object System.Windows.Forms.FolderBrowserDialog | |
| $dialog.Description = "リンクする先のディレクトリを選択" | |
| if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { | |
| $target = $dialog.SelectedPath | |
| } | |
| else { | |
| Write-Output("キャンセルされました。処理を中断します。") | |
| exit | |
| } | |
| } | |
| Write-Output($target + " が選択されました。") | |
| $saveDialog = New-Object System.Windows.Forms.SaveFileDialog | |
| $saveDialog.FileName = Split-Path $target -Leaf | |
| $saveDialog.Title = "出力先ディレクトリを指定" | |
| $saveDialog.Filter = "すべてのファイル(*.*)|*.*" | |
| if ($saveDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { | |
| Write-Output($saveDialog.FileName + " が選択されました。") | |
| $outputDir = Split-Path $saveDialog.FileName -Parent | |
| $symlinkName = Split-Path $saveDialog.FileName -Leaf | |
| Push-Location $outputDir | |
| New-Item -ItemType SymbolicLink -Name $symlinkName -Target $target | |
| Pop-Location | |
| } | |
| else { | |
| Write-Output("キャンセルされました。処理を中断します。") | |
| exit | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment