Skip to content

Instantly share code, notes, and snippets.

@Deployment-MX
Last active March 11, 2024 23:22
Show Gist options
  • Save Deployment-MX/847e2b63c3a87d47f575e137ae5a3740 to your computer and use it in GitHub Desktop.
Save Deployment-MX/847e2b63c3a87d47f575e137ae5a3740 to your computer and use it in GitHub Desktop.
Create a Shortcut in Desktop using Microsoft Intune
function Create-WebShortcut {
param (
[Parameter(Mandatory)]
[String] $Path,
[Parameter()]
[String] $WebsiteUrl,
[Parameter()]
[String] $Icon
)
#Edge
$edgePath = "%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($Path)
$Shortcut.TargetPath = $edgePath
$Shortcut.Arguments = $WebsiteUrl
$Shortcut.IconLocation = $Icon
$Shortcut.Save()
[Runtime.InteropServices.Marshal]::ReleaseComObject($WshShell) | Out-Null
}
#Name of the shortcut
$shortcutName = "DeploymentMX"
#Icon file best to use a website
$icon = "https://deployment.mx/imagenes/worldwide-web-icon-9.ico"
$iconPath = "C:\ProgramData\WebpageShortcut\worldwide-web-icon-9.ico"
#Link of the webseite
$websiteUrl = "https://www.deployment.mx"
#OutputFolder
$outputFolder = "C:\temp"
if (-not (Test-Path $outputFolder)) {
New-Item -ItemType Directory -Path $outputFolder | Out-Null
Write-Host "Temporary folder created at: $outputFolder"
} else {
Write-Host "Temporary folder already exists at: $outputFolder"
}
$path = Join-Path -Path $outputFolder -ChildPath "$shortcutName.lnk"
#Create shortcut
Invoke-WebRequest -Uri $icon -OutFile "$outputFolder\worldwide-web-icon-9.ico"
Create-WebShortcut -Path $path -WebsiteUrl $websiteUrl -Icon $iconPath
Start-Sleep -Seconds 2
#Name of the shortcut
$shortcutName = "DeploymentMX"
$iconPath = "C:\ProgramData\WebpageShortcut\"
$icontemp = "C:\Temp\"
if (-not (Test-Path $iconPath)) {
New-Item -ItemType Directory -Path $iconPath | Out-Null
Write-Host "Temporary folder created at: $iconPath"
} else {
Write-Host "Temporary folder already exists at: $iconPath"
}
#$ScriptPath = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definition)
$ScriptPath = "C:\Temp"
Get-ChildItem -Path $icontemp -Filter *.* | ForEach-Object {
Copy-Item -Path $_.FullName -Destination $iconPath -Force
}
Copy-Item -Path "$ScriptPath\$shortcutName.lnk" -Destination "$Env:Public\Desktop"
Start-Sleep -Seconds 2
#Name of the shortcut
$shortcutName = "DeploymentMX"
if (Test-Path -Path "$Env:Public\Desktop\$shortcutName.lnk"){
Write-Output "0"
}
######remove icon
#Name of the shortcut
#$shortcutName = "DeploymentMX"
#$iconPath = "C:\ProgramData\WebpageShortcut\"
#Remove-Item -Path "$Env:Public\Desktop\$shortcutName.lnk"
#Remove-Item -Path $iconPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment