intune deployment help

Copper Contributor

i have tested my script to run locally and it does work. When I intune wrap and deploy the package it does not work. Can anyone tell me why when its goes thru intune it's spit an error saying it couldnt detect after it was installed but it never installs.

 

$sourceFolderPath = "C:\Users\Randolph\OneDrive - RedCup, Inc\Intune Packages\Chart Templates 11_30_23" # Specify the path to the source folder containing the new files
$specificSubfolder = "Charts" # Copy files from the specific subfolder in the source folder to the destination folder
$destinationFolderPath = "$env:APPDATA\Microsoft\Templates\Charts" # Specify the path to the destination folder


$specificSubfolderPath = Join-Path -Path $sourceFolderPath -ChildPath $specificSubfolder

# Remove the destination folder if it exists, excluding specific folders
if (Test-Path -Path $destinationFolderPath) {
$excludedFolders = @(".dotm", "Document Themes", "SmartArt Graphics", "LiveContent")
$itemsToExclude = Get-ChildItem -Path $destinationFolderPath -Directory | Where-Object { $excludedFolders -contains $_.Name }
$itemsToDelete = Get-ChildItem -Path $destinationFolderPath -File | Where-Object { $excludedFolders -contains $_.Name.Split(".")[0] }

$itemsToDelete | Remove-Item -Force
$itemsToExclude | ForEach-Object { Remove-Item -Path $_.FullName -Recurse -Force }
}

# Create the destination folder
New-Item -ItemType Directory -Path $destinationFolderPath | Out-Null

# Copy files from the specific subfolder in the source folder to the destination folder using robocopy with /MIR switch
Robocopy $specificSubfolderPath $destinationFolderPath /MIR

2 Replies

Hello @Keke_000 

 

Welcome to the Microsoft community, my name is Recep I'll be happy to help you today.

 

  • Ensure that the PowerShell execution policy allows the script to run. You can set the execution policy to Bypass for the script deployment. Add the following lines at the beginning of your script:

# Set Execution Policy to Bypass

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

This ensures that the script can run even if there are restrictions in place.

  • Add logging to your script to capture any errors or information. Redirect output and error streams to a log file:

$logFilePath = "$env:TEMP\ScriptLog.txt"

Start-Transcript -Path $logFilePath -Append

 

# Your existing script code here

 

Stop-Transcript

After the deployment, check the log file for any errors or unexpected behavior.

 

  • When running scripts via Intune, ensure that the paths and environment variables are accessible and valid for the system account under which Intune runs.
  • Use the absolute paths wherever possible.
  • Verify that the system account has the necessary permissions to read and execute from the specified paths.
  • Ensure that your Intune deployment configuration includes a detection script that accurately identifies whether your script has successfully executed. Without a detection script, Intune might not correctly detect the success of your deployment.

For example, create a separate PowerShell script for detection, and then configure Intune to use it. The detection script might check for the existence of a file or registry key that indicates a successful deployment.

# Detection script example

$filePath = "$env:APPDATA\Microsoft\Templates\Charts\SomeFile.txt"

if (Test-Path -Path $filePath) {

    Write-Output "Success"

} else {

    Write-Output "Failure"

}

Configure this script as the detection method in your Intune deployment.

 

 

 

If I have answered your question, please mark your post as Solved

If you like my response, please give it a Like :smile:

Appreciate your Kudos! Proud to contribute! :)

 

$env:APPDATA would be the first thing I would check out... as that one corresponds to the appdata from the account that triggers the script
And assuming you are running that script in system? (not the signed in user) it would resolve to the system appdata folder