polina-c
polina-c

Reputation: 7077

How to create symbolic link for non-existing folder?

I'd like to create link to a folder on desktop of remote computer. I do not have permissions to execute scripts on that computer, but I can copy files to that computer.

My idea was to create link to folder on local computer and then copy the link to remote computer. But, I am getting error New-Item : Cannot find path 'C:\SomeFolder' because it does not exist.

Here is my command:

New-Item -Path "c:\Users\pocherka\Desktop\link" -ItemType SymbolicLink -Value "c:\SomeFolder" -Force

Any ideas for workaround?

Upvotes: 1

Views: 3547

Answers (2)

Ranadip Dutta
Ranadip Dutta

Reputation: 9133

You can do using mklink also . Make sure that the destination folder is available . You can use the Test-Path to check that :

$destination = "c:\SomeFolder"
if(Test-Path $destination)
{
cmd /c mklink "c:\Users\pocherka\Desktop\link" $destination
# OR you can use the new-item also. Just commented in the below line
# New-Item -Path "c:\Users\pocherka\Desktop\link" -ItemType SymbolicLink -Value $destination
}
else
{
New-Item $destination -ItemType Directory -Force
cmd /c mklink "c:\Users\pocherka\Desktop\link" $destination
}

Hope it helps

Upvotes: 1

Maxime Franchot
Maxime Franchot

Reputation: 1103

Try adding the -force parameter:

New-Item -Path "c:\Users\pocherka\Desktop\link" -ItemType SymbolicLink -Value "c:\SomeFolder" -force

Upvotes: 2

Related Questions