Create an EXE Shortcut in Start menu
#create EXE shortcut
$ShortcutStartmenu = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Application\Shortcut.lnk"
$path = "PathToEXE"
New-Shortcut -Path $ShortcutStartmenu -TargetPath $path-IconIndex 0 -Description "EXEName"
Create an URL Shortcut on Desktop and Start menu
#create URL shortcut
$ShortcutDesktop = "$env:Public\Desktop\Shortcut.url"
$ShortcutStartmenu = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Shortcut.url"
$url = "https://LinkToWebsite"
$edgeIconPath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
New-Shortcut -Path $ShortcutDesktop -TargetPath $url -IconLocation $edgeIconPath -IconIndex 0 -Description "LinkName"
New-Shortcut -Path $ShortcutStartmenu -TargetPath $url -IconLocation $edgeIconPath -IconIndex 0 -Description "LinkName"
Create multiple Shortcuts with argument to an ini-file containing the Computername
#get device name
$deviceName = $env:COMPUTERNAME
#define Start Menu Programs path
if (!(Test-Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Application XYZ")) {
New-Item -ItemType Directory -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Application XYZ"
}
$startMenuPath = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Application XYZ"
#ensure the directory exists
if (-not (Test-Path -Path $startMenuPath)) {
New-Item -ItemType Directory -Path $startMenuPath -Force
}
$shortcuts = @(
@{
Name = "ABC"
Target = "\\PathToEXEonShare"
Arguments = "/ini=`"\\Share\Computers\$deviceName\\Application XYZ.ini`""
},
@{
Name = "DEF"
Target = "\\PathToEXEonShare"
Arguments = "/ini=`"\\Share\Computers\$deviceName\\Application XYZ.ini`""
},
@{
Name = "GHI"
Target = "\\PathToEXEonShare"
Arguments = "/ini=`"\\Share\Computers\$deviceName\\Application XYZ.ini`""
}
)
foreach ($shortcut in $shortcuts) {
try {
Write-Log -Message "Creating shortcut '$($shortcut.Name)' in Start Menu." -Severity 1
$WshShell = New-Object -ComObject WScript.Shell
$lnk = $WshShell.CreateShortcut("$startMenuPath\$($shortcut.Name).lnk")
$lnk.TargetPath = $shortcut.Target
$lnk.Arguments = $shortcut.Arguments
$lnk.Save()
Write-Log -Message "Successfully created shortcut: $($shortcut.Name)" -Severity 1
}
catch {
Write-Log -Message "Failed to create shortcut '$($shortcut.Name)': $_" -Severity 3
}
}