SymbolicLinks pre V5

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Alex Franco Alex Franco 1 year, 3 months ago.

  • Author
    Posts
  • #32450
    Profile photo of Alex Franco
    Alex Franco
    Participant

    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
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
    Profile photo of Mark Hammonds
    Mark Hammonds
    Participant

    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
    Profile photo of Alex Franco
    Alex Franco
    Participant

    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

You must be logged in to reply to this topic.