Trying to make a symbolic link to a Powershell script on a remote server

1.3k views Asked by At

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. Becasue I have 2003 and 200! servers i first check if the patch exists..

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\powershell.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, there seems to be no target.

It seems when i don'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.

Any tips / ideas?

1

There are 1 answers

0
alroc On BEST ANSWER

Symlinks need to point to individual files - they're a pointer to another location on disk. They cannot (to my knowledge) point to an executable with parameters passed.

A .LNK file is a specific kind of file. You can't just just create a symlink, call it .lnk, and expect it to work the same as if you'd created a new shortcut on your desktop.

Your UNC paths are malformed - they need to begin with two backslashes (\\), not one.