Intune

Copper Contributor

good day

Hope someone can assist me, I want to create a intune package that copy a folder from a network server to the local C drive of the computer, after the copy has finish I want it to automatically deploy the installation file in the folder that's copied to the local C drive.

I have try many steps but it looks like the copy does not happen, is there any advice on how I can better this steps or any scripts I can use? any advice will be helpful.  

14 Replies

@Werner2024 These steps can be achieved with a powershell script that you can package as intunewin and then deploy as an app. Are you already doing these steps? If so, can you share the script with us?

Hi Jos van der Vaart

Thanks you for the reply, here is the script i am using noe, might not be the best but it works if you run it on the machine self, but not trough Intune

$sourceFolderPath = " # Specify the network path to the shared folder
$destinationFolderPath = # Specify the local destination path on your laptop
$softwarelocation =

#Write-Host $destinationFolderPath
#Write-Host $sourceFolderPath


# Create the destination folder if it does not exist
if (-not (Test-Path -Path ${destinationFolderPath})) {
try {
New-Item -ItemType Directory -Path ${destinationFolderPath} -ErrorAction Stop
Write-Host "Folder created at ${destinationFolderPath}"
}
catch {
Write-Host "Error creating folder: ${destinationFolderPath}"
return
}
}
else {
#Write-Host "Destination folder already exists."
}

# Use xcopy to copy files from the shared folder to the local destination
try{
$xcopyCommand = "Copy-Item -Path "File Location" -Destination C:\ -Recurse"
Invoke-Expression -Command $xcopyCommand
Write-Host "Files copied from ${sourceFolderPath} to ${destinationFolderPath}."
}

catch {
Write-Host "Error copying files: $_"
}

#Wait for 15 seconds
Start-Sleep -Milliseconds 15000

cd $softwarelocation

Start-Process -FilePath .\ "Install file"-ArgumentList "/S" -Wait

Hey Werner, Thanks for sharing.

Have you tried running it locally and could you share a anonimised error log?

it looks like that you also install it in the same script.

Maybe it's easier to use a .zip containing the set of files, copying it over and using unzip archive command to achieve easier copying to the folder you want,

Expand-Archive -LiteralPath <PathToZipFile> -DestinationPath <PathToDestination>

I have done this due to an AX installation and used a zip to move the 4gb big file towards a temp folder on the endpoint, then unzipping it and using the install script to install it.

Hi Tim,

Thanks for the info will definitely give it a try, my only concern is the copy process from the server to the local machine does not happen, so I am stuck there.

The error logs does not give me any error's or false status, the app show installed on Intune console but on the endpoint nothing is happening. what I have notice is that it shows that the app is downloading and installing then a min after that it fails.
Hi Werner,

Thanks for sharing, but how do you roll out this script through Intune. Is this through an app or a script? I would advise you to at least roll it out as an app.
I have a poweshell script that I have build an .intunewin package, then from there I upload into Intune as an Windows app (Win32) app to deploy.
Uhh... how are you deploying that app? I assume in the system context? as the system account will probably not have access to that file share on the server...
Hi Rudy

Yes that's my thoughts also but was not sure if that could be the cause or is the script the issue, hens the logs did not show anything weird I figured maybe that might be an access issue.

any suggestions what we can do to test the access? intune does run with a services account and I doubt that you can create a separate folder only allowing that account to the folder.
Hi Werner,

You can test the access by running your script locally as SYSTEM. You can do that by downloading PSEXEC.EXE from Microsoft (SysInternals Tools) and running "psexec.exe -accepteula -s -i cmd.exe" or "start \\live.sysinternals.com\tools\psexec.exe -accepteula -s -i cmd.exe"

In the scenario you describe you would probably need to delegate Read rights on the source folder to something like "Everyone" to make this work.
Hi James,

Will definitely test the access, the other problem we also facing is that policy rules does not allow us to give "everyone" access to any folder, I will test the access if thats the case I will see what we can do from there or get a work around.

Thanks for all the advice really appreciate it.
Hey Werner,

No problem! What is the command you are using in intune? maybe the installment is dedicated to run as USER with Elevated rights.

greets,
tim
I use the below command

Powershell.exe -NoProfile -ExecutionPolicy ByPass -File .\script.ps1

This is mine and works flawlessly in this scenario

powershell.exe -executionpolicy bypass -file "Install.ps1"

My AX installation script looks like the following:
$tempExtractPath = "C:\Temp\ExtractedFiles"
New-Item -ItemType Directory -Path $tempExtractPath -Force | Out-Null

# Pak het .zip-bestand uit naar de tijdelijke map
Expand-Archive -Path $zipFilePath -DestinationPath $tempExtractPath -Force


Then I use the start-process to install the AX
Thanks Tim

Will give this a try definitely