Forum Discussion
Script status showing failed however, the desktop Icon is installed. Deployed script via Intune
- Nov 06, 2023
I also used Chatgpt and used a script and it worked.
This is what I used:# Variables creating local folder and download .ico file
$LocalIconFolderPath = "C:\Intune\xxxxxxxxIntranet"
$SourceIcon = "https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxlogo-wo-wb/xxxxxxxxlogo-wo-wb.ico"
$DestinationIcon = "C:\Intune\xxxxxxxxIntranet\xxxxxxxxlogo-wo-wb.ico"# Initialize exit code
$exitCode = 0# Check if the desktop shortcut already exists
try {
$new_object = New-Object -ComObject WScript.Shell
$destination = $new_object.SpecialFolders.Item('AllUsersDesktop')
$source_path = Join-Path -Path $destination -ChildPath '\\Global Intranet.lnk'
if (Test-Path $source_path) {
Write-Host "Desktop shortcut already exists. Skipping installation."
} else {
# Step 1 - Create a folder to place the URL icon
try {
New-Item $LocalIconFolderPath -Type Directory -ErrorAction Stop
} catch {
Write-Host "Error creating folder: $_"
$exitCode = 1 # Set exit code to indicate an error
}# Step 2 - Download an ICO file from a website into the previously created folder
try {
curl $SourceIcon -o $DestinationIcon -ErrorAction Stop
} catch {
Write-Host "Error downloading ICO file: $_"
$exitCode = 2 # Set exit code to indicate an error
}# Step 3 - Add the custom URL shortcut to your Desktop with a custom icon
if ($exitCode -eq 0) {
try {
$new_object = New-Object -ComObject WScript.Shell
$destination = $new_object.SpecialFolders.Item('AllUsersDesktop')
$source_path = Join-Path -Path $destination -ChildPath '\\Global Intranet.lnk'
$source = $new_object.CreateShortcut($source_path)
$source.TargetPath = 'https://xxxxxxxxxxxxx.sharepoint.com/sites/GlobalIntranet?web=1'
$source.IconLocation = "C:\Intune\xxxxxxxxIntranet\xxxxxxxxlogo-wo-wb.ico"
$source.Save()
} catch {
Write-Host "Error creating shortcut: $_"
$exitCode = 3 # Set exit code to indicate an error
}
}
}
} catch {
Write-Host "Error checking for desktop shortcut: $_"
$exitCode = 4 # Set exit code to indicate an error
}# Exit the script with exit code 0 to indicate success, even if steps were skipped
Exit 0