Powershell create shortcut to server root share
-
The below is what I have, and it works on my system, but not others. I had this completed >.< but I dirped, and erased the thumb drive that had the only copy.
The goal is to create a shortcut on any given users desktop to the specified server, not to the sub-share under the root.
IE: Target>Server1
Not Target>Server1>Share
$TargetFile = "\\server.domain.com" $ShortcutFile = "$env:Public\Desktop\FileServer.lnk" $WScriptShell = New-Object WScript.Shell -Verbose $Shortcut = $WScriptShell.CreateShortcut($ShortcutFile) $Shortcut.TargetPath = $TargetFile $Shortcut.Save()
-
@dustinb3403 said in Powershell create shortcut to server root share:
The below is what I have, and it works on my system, but not others. I had this completed >.< but I dirped, and erased the thumb drive that had the only copy.
The goal is to create a shortcut on any given users desktop to the specified server, not to the sub-share under the root.
IE: Target>Server1
Not Target>Server1>Share
$TargetFile = "\server.domain.com"
$ShortcutFile = "$env:Public\Desktop\FileServer.lnk"
$WScriptShell = New-Object WScript.Shell -Verbose
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()Do you get any error messages?
Seems to me like your $ShorcutFile should be:
$ShortcutFile = "$($env:Public)\Desktop\FileServer.lnk"
? -
@dafyre said in Powershell create shortcut to server root share:
Do you get any error messages?
Seems to me like your $ShorcutFile should be:
$ShortcutFile = "$($env:Public)\Desktop\FileServer.lnk"
?A bunch of random error messages about object not found (powershell objects).
Gah I wish I had backed up this stupid script. .
-
I got it.
$WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$Home\Desktop\FileServer.lnk") $Shortcut.TargetPath = "\\server.domain.com" $Shortcut.Save()
-
ps. I made backup now.
-
I assume you don't want to use GPO for this.
-
@dbeato said in Powershell create shortcut to server root share:
I assume you don't want to use GPO for this.
Unfortunately for this case that isn't an option. Extenuating circumstances. . . .
-
@DustinB3403 what about the public desktop instead of hte user desktop?
Then it will always be there, regardless of who logs in.
-
@jaredbusch said in Powershell create shortcut to server root share:
@DustinB3403 what about the public desktop instead of hte user desktop?
Then it will always be there, regardless of who logs in.
Not a huge concern for our use cases as we usually just end up wiping a system and reloading between user changes.
I thought about it, but it wasn't critical and as we change things around it becomes a pain to remove the old links to systems that may not exist any more.