Automatically sending Task Sequence logs to SharePoint when MECM/MDT deployment fails
In this post I will show you a script allowing you to automatically send MECM/MDT Task Sequence logs to SharePoint when a Task Sequence fails.
Context
- You use MDT or MECM
- You deploy OS through a Task Sequence
What do we want ?
When an error occurs on a device during a Task Sequence, you have to go to the device to check logs.
It can be a bit borrying to check logs from the remote device.
With this script, when a Task Sequence is failing, all logs will be automatically sent to a SharePoint and a notification displayed on Teams.
This way you can check logs from your device and everyone from your team (if they have access on the SharePoint) can see logs.
The solution
The solution results in few steps:
- Create an Azure app registration
- Add permission
- Create an MECM package
- Add it to th Task Sequence
- The script will use the Azure app
- It will send logs
- Send a Teams notification about the purge
Get the script
Click on the below GitHub picture to get the script
How to use the script ?
SharePoint information
Add information relative to your SharePoint app line 29 to 32.
We will see a different ways to proceed later in the post.
Add your webhook in the $Webhook_URL variable.
Teams notification
The teams notification looks like as below:
You can easily configure it in the ps1 file.
Configuring the Azure app
See my post here about how to upload files on SharePoint. You will see how to create and configure the Azure app registration.
Creating Teams webhook
Purpose: In this part, we will create a connector on a Teams channel allowing us to automate ability to send Teams notif.
For that, we will proceed as below:
1. Go to your channel
2. Click on the ...
3. Click on Connectors
4. Go to Incoming Webhook
5. Type a name
6. Click on Create
7. Copy the Webhook path
Implement in MECM or MDT
Create the MECM package
1. Go to Software Library
2. Go to Application Management then Packages
3. Do a right click and select Create Package
4. Type a name
5. Check This package contains source files
6. Click on Browse, then select the folder containing the wizard
7. Click on Next
8. Select Do not create a program
9. Click on Next
10. Click on Next
11. Click on Close
Distribute the package
1. Do a right-click on your package
2. Select Distribute Content
3. Click on Next
4. Click on Add and select Distribution Point
5. Select your DP and click on OK
6. Click on Next
7. Click on Next
8. Click on Close
Sending on failure
The goal there is to send logs if the TS fails.
For this we need know when it fails.
We can proceed as below:
1. On each step of your TS go to the Options part
2. Uncheck Continue on error
3. Go at the end of your TS
4. Click on Add > New group
5. Type a name
6. On this group,go to Options
7. Configure _SMSTSLastActionSucceeded to False
Implement in Task Sequence
1. Edit your Task Sequence
2. Go to group Send Logs on Failure
3. Click on Add > General > Run PowerShell Script
4. In package part browse your package
5. In script name, type Send_TSLogs_to_SharePoint.ps1
6. In Execution policy choose Bypass
Next step is to specify how to authenticate to the Azure app.
We will configure two variables for storing both app ID and secret.
We will proceed as below:
1. Go to the beginning of the TS
2. Clik on Add > General > Set Dynamic Variables
3.Click on Add Variable
4. Click on Custom variable
5. Type TS_Client_ID
6. Check Do not display the value
7. In Value and Confirm value type client id
8. Click on Add Variable
9. Click on Custom variable
10. Type TS_Client_Secret
11. Check Do not display the value
12. In Value and Confirm value type the SharePoint secret
13. Click on Add Variable
14. Click on Custom variable
15. Type TS_Tenant_Name
16. Check Do not display the value
17. In Value and Confirm value type the name of your Azure tenant
18. Click on Add Variable
19. Click on Custom variable
20. Type TS_SharePoint_Site_ID
21. Check Do not display the value
22. In Value and Confirm value type the id of the SharePoint site
Send notif on Teams
There we will choose if we want to send a notif on Teams in case of failure to inform that logs are available.
The teams notif will give below information:
- Name of the device
- Log ZIP name
We will proceed as below:
1. Go to the beginning of the TS
2. Clik on Add > General > Set Dynamic Variables
3. Click on Add Variable
4. Click on Custom variable
5. In Variable, type TS_Send_Teams_Notif
6. In Value, type True or False nothing else
2 commentaires
Awesome, will be using it. Thanks for sharing!
Could you please explain which wizard you are referring to in step no. 6-
Implement in MECM or MDT
Create the MECM package
6. Click on Browse, then select the folder containing the wizard
Enregistrer un commentaire