SymbolicLinks pre V5

Welcome Forums General PowerShell Q&A SymbolicLinks pre V5

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
2 years, 10 months ago.

  • Author
    Posts
  • #32450

    Participant
    Points: 0
    Rank: Member

    I got a script I'd like to deploy through group policy, but I wrote the script in PowerShell version 5 and it uses New-Item -ItemType SymbolicLink, unfortunately most computers in the domain are version 3. The SymbolicLink item type wasn't introduced until version 5 so my script isn't working. Is there a pre-version5 way of doing this?

    Thanks in advance!

  • #32451

    Member
    Points: 0
    Rank: Member

    Not built into PowerShell, no. You could either find a .NET library that exposes this functionality (or write your own P/Invoke code, which is possible but not always easy), or you can just use something like junction.exe ( https://technet.microsoft.com/en-CA/sysinternals/bb896768.aspx )

  • #32454

    Participant
    Points: 0
    Rank: Member

    this is how I did it with mklink.exe. mklink is native to windows

    https://technet.microsoft.com/en-us/library/cc753194.aspx

    $date = @()
    $shadows = get-wmiobject win32_shadowcopy
    $num = 0
    Foreach($shadow in $shadows){
    $date += New-Object PSObject -Property ([ordered]@{Date = ("$num : " + [datetime]::ParseExact($shadow.InstallDate.Split(".")[0], "yyyyMMddHHmmss", $null))})
    $num ++
    }
    cls
    $date | sort date -Descending
    ""
    $val = (Read-Host -Prompt "Please select restore date")
    $val2 = (Read-Host -Prompt "Please enter UserId")
    cmd.exe /c mklink /d "c:\ShadowCopy" ($shadows[$val].DeviceObject + "\users\$($val2)")
    Invoke-Item "C:\ShadowCopy"
    
  • #32455

    Participant
    Points: 0
    Rank: Member

    Looks like that Junction only does junctions on the local computer and can't reach across the network. Maybe I'm looking at this wrong and instead of just making it work I should push out an update to v5 through group policy

The topic ‘SymbolicLinks pre V5’ is closed to new replies.