PowerShell 5.0 includes significant new features that extend its use and improve its usability. In this blog post, we will manage symbolic links using PowerShell. Thanks to WMF 5, now it’s pretty easy to create a symbolic link.
New-Item, Remove-Item, and Get-ChildItem have been enhanced to support creating and managing symbolic links. Now, you can create symbolic links in a single line which is a great thing! Use the -ItemType parameter by specifying SymbolicLink as the value of this parameter.
Below is an example. First I will create a simple file:
PS > New-Item -ItemType "File" -Path "C:\Users\Nicolas\Documents" -Name "MyFile.txt" -Value "Welcome" Directory: C:\Users\Nicolas\Documents Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 09.10.2016 17:24 7 MyFile.txt
MyFile.txt is created.
Now, I will create the symbolic link:
PS > New-Item -ItemType "symboliclink" -Target "C:\users\Nicolas\Documents\MyFile.txt" -name "MySymbolicLink" Directory: C:\Users\Nicolas Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---l 09.10.2016 17:24 0 MySymbolicLink
Its’ done!
If you want to remove your symbolic link:
PS > Remove-Item -Path "C:\Users\Nicolas\MySymbolicLink"
Now, Get-ChildItem cmdlet can display SymbolicLink file type:
PS > gci Directory: C:\users\Nicolas Mode LastWriteTime Length Name ---- ------------- ------ ---- d-r--- 01.10.2016 09:52 Contacts d-r--- 01.10.2016 09:52 Desktop d-r--- 09.10.2016 17:28 Documents d-r--- 01.10.2016 09:52 Videos -a---l 09.10.2016 17:24 0 MySymbolicLink
Thanks for reading! You can follow me on Twitter @PrigentNico