Powershell script issues

Copper Contributor

Hi everyone,

I would like some help related with some scripts in Microsoft Endpoint Manager.

We already create a script that change name of the device when it deploy autopilot. The script works perfectly but when we see the status of the script in intune, its showed like failed!.

 

I would like to know if this script need something else. 

 

Below is the script that we just create.

Like i said, when this script is deploy in a device, it works perfectly!!

 

But when we like to see the status of that script in intune it show like this!

Oscarrdz_1-1616197233418.png

 

 

Oscarrdz_0-1616196986428.png

Thanks 

 

1 Reply
you could try to add a try / if /else.

Here is an example.

Try {
$Result = get-winevent -FilterHashTable @{LogName="Application";StartTime=(get-date).Addseconds(-600)}|Where-Object{($_.id -eq 0) -and ($_.message -like "*added to the Administrators group*")} | ft message
$ID = $Result | measure-Object
If ($ID.Count -lt 5)
{
Write-Output "No users added to the local admin group"
Exit 0
}
Else
{
Write-Output $result
Exit 1001
}
}
catch
{
Write-Warning "Value Missing"
Exit 1001
}