Forum Discussion

newtotechcom-J's avatar
newtotechcom-J
Brass Contributor
Oct 31, 2023

Script status showing failed however, the desktop Icon is installed. Deployed script via Intune

I have the following script deployed in Intune.

The script is working fine- it is deploying the desktop icon that I want. But the issue is even though the desktop icon is there- it is still showing as status failed in Intune status page

#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
New-Item $LocalIconFolderPath -Type Directory

#Step 2 - Download a ICO file from a website into previous created folder
curl $SourceIcon -o $DestinationIcon

#Step 3 - Add the custom URL shortcut to your Desktop with 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()
 

 

  • Rudy_Ooms_MVP 

     

    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

  • J-D's avatar
    J-D
    Copper Contributor
    Try adding an exit code to the end of your script, Intune relies on them to return a successful installation or a failed installation.
      • Rudy_Ooms_MVP's avatar
        Rudy_Ooms_MVP
        MVP
        didnt 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
        }
  • rahuljindal-MVP's avatar
    rahuljindal-MVP
    Bronze Contributor
    What does the agentexecutor log say on the devices in question? Alternatively, you can try adding logic for error handling and\or deploy using a Win32 app instead.
  • Please try adding Start-Transcript c:\windows\temp\desktopicon.log to the start of the script and End-Transcript at the end of the script. Deploy and read the log afterwards, it should give you an insight of the issue

Resources