I'm trying to create a symbolic link with mklink through a Powershell script to a Powershell script on a remote server. this link should come on the desktop of all users.

if(!(test-path -path \$hostname\c$\Users)) { Copy-Item -Path "\dsfpad\Nagios\Nagios_Downtime\Nagios - Schedule Downtime.lnk" -Destination "\$hostname\c$\Documents and Settings\All Users\Desktop\Nagios - Schedule Downtime.lnk" } else { $s=New-PSSession -ComputerName $hostname Enter-PSSession $s Invoke-Command -Session $s -ScriptBlock {& cmd /c mklink "C:\Users\Public\Desktop\Nagios - Schedule Downtime.lnk" "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -file c:\Nagios\Nagios_Downtime_Window_NRDP.ps1"} exit-pssession
remove-pssession $s }

I get symbolic link created for C:\Users\Public\Desktop\Nagios - Schedule Downtime.lnk <<===>> C:\WINDOWS\system32\WindowsPowerShell\v1.0\po wershell.exe -file c:\Nagios\Nagios_Downtime_Window_NRDP.ps1

But when I try to execute the link on a server, it doesn't work. looking at the Target of the link, therer seems to be no target...

Any tips / ideas?

  • it seems when i dont't use C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -file in the target, I do get a target in the lnk file, but it does not execute the script... – willemdh Dec 10 '13 at 11:43
  • Creating a symlink requires admin level on windows, and the link target must exist. There are multiple types of them, one is similar to hardlink, one is to bind-mounts, and the third is the normal symlink. You know: hope it helps :-) – user259412 Dec 10 '13 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.