SymbolicLinks pre V5

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

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

    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

    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 ( )

  • #32454
    Profile photo of Mark Hammonds
    Mark Hammonds

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

    $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 ++
    $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

    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.