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
As I'm using script.
- Nov 03, 2023didnt test it yet... but i just asked chatgpt to do it for me
# Variables creating local folder and download .ico file
$LocalIconFolderPath = "C:\Intune\Xxxxxxxxxxxxxxx"
$SourceIcon = "https://xxxxxxxx/xxxxxxxxlogo-wo-wb/xxxxxxxxlogo-wo-wb.ico"
$DestinationIcon = "C:\Intune\Xxxxxxxxxxxxxxx\xxxxxxxxlogo-wo-wb.ico"
# Step 1 - Create a folder to place the URL icon
if (!(Test-Path $LocalIconFolderPath -PathType Container)) {
New-Item $LocalIconFolderPath -Type Directory
if ($?) {
Write-Host "Folder created successfully."
} else {
Write-Host "Failed to create the folder."
exit 1
}
}
# Step 2 - Download an ICO file from a website into the previously created folder
Invoke-WebRequest -Uri $SourceIcon -OutFile $DestinationIcon
if ($?) {
Write-Host "ICO file downloaded successfully."
} else {
Write-Host "Failed to download the ICO file."
exit 1
}
# Step 3 - Add the custom URL shortcut to your Desktop with a custom icon
$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\Xxxxxxxxxxxxxxx\xxxxxxxxlogo-wo-wb.ico"
$source.Save()
if ($?) {
Write-Host "Shortcut created successfully."
exit 0
} else {
Write-Host "Failed to create the shortcut."
exit 1
}- newtotechcom-JNov 06, 2023Brass Contributor
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