powershell to create a folder junction RRS feed

  • General discussion

  • I was provided a batch script that creates a folder junction. To be honest, I've never come across this before in my career, but I need to convert the command into PowerShell.

    Here's the code as it is in the batch script.

    mklink /J %windir%\"System32\config\systemprofile\AppData\Local\Downloaded Installations\{DB5846B2-62BA-4A3D-8638-06C78DCB22CA}" %windir%\"SysWOW64\config\systemprofile\AppData\Local\Downloaded Installations\{DB5846B2-62BA-4A3D-8638-06C78DCB22CA}"

    As per PowerShell v5 new features, there's a native way of accomplishing a folder junction, but I can't seem to figure out how to accomplish this.  The Get-Help information isn't much help, and I haven't been able to find any examples on the net either.

    New-Item -ItemType Junction
    I know there's more to the command, I just can't figure it out what switches and values are needed to accomplish this.

    Friday, December 2, 2016 2:22 PM

All replies

  • -ItemType [<String>]
        Specifies the provider-specified type of the new item. Starting in Windows PowerShell 5.0, you can create symbolic
        links by specifying SymbolicLink as the value of this parameter.


    Friday, December 2, 2016 3:05 PM
  • yes that is where I found the reference, but if you do a mklink /?, the /J parameter specifies that it creates a directory junction.

    Either way, specifying SymbolicLink or Junction, I can't seem to figure out how to use it.

    Friday, December 2, 2016 3:40 PM
  • D:\scripts> New-Item -Name testlink -ItemType SymbolicLink -Path d:\test -Value d:\test2
        Directory: D:\test
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d----l        12/2/2016  10:45 AM                testlink
    D:\scripts> get-item d:\test\testlink
        Directory: D:\test
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    d----l        12/2/2016  10:45 AM                testlink


    Friday, December 2, 2016 3:46 PM
  • I'm missing something still. If I run  mklink /J c:\tom c:\tom2, I get a different-looking icon on the tom folder.  But if I use what you provided, I get a different result.  I tried also using what you provided but replaced the type with Junction, and it still didn't create it like the mklink command.  I'm not familiar at all with symbolic links nor junctions, so I'm really not sure if what you provided is doing what was provided in the batch file.
    Friday, December 2, 2016 8:23 PM
  • I figured it out.
    Saturday, December 3, 2016 1:48 AM
  • Dear Thomas,

    Glad that you found out the issue and solved it. But my sincere suggestion is if you are posting any question here in this forum, kindly make sure that your question points the exact issue and the code you are trying to run and the exact error that you are facing. Also if the issue is solved by yourselves, then kindly share the same as it might help the google searchers for a solution.

    Naveen Basati

    Saturday, December 3, 2016 7:32 AM