Powershell script issues

%3CLINGO-SUB%20id%3D%22lingo-sub-2224051%22%20slang%3D%22en-US%22%3EPowershell%20script%20issues%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2224051%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20everyone%2C%3C%2FP%3E%3CP%3EI%20would%20like%20some%20help%20related%20with%20some%20scripts%20in%20Microsoft%20Endpoint%20Manager.%3C%2FP%3E%3CP%3EWe%20already%20create%20a%20script%20that%20change%20name%20of%20the%20device%20when%20it%20deploy%20autopilot.%20The%20script%20works%20perfectly%20but%20when%20we%20see%20the%20status%20of%20the%20script%20in%20intune%2C%20its%20showed%20like%20failed!.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20like%20to%20know%20if%20this%20script%20need%20something%20else.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBelow%20is%20the%20script%20that%20we%20just%20create.%3C%2FP%3E%3CP%3ELike%20i%20said%2C%20when%20this%20script%20is%20deploy%20in%20a%20device%2C%20it%20works%20perfectly!!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20when%20we%20like%20to%20see%20the%20status%20of%20that%20script%20in%20intune%20it%20show%20like%20this!%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Oscarrdz_1-1616197233418.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F265777i697EA387CA72BA32%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Oscarrdz_1-1616197233418.png%22%20alt%3D%22Oscarrdz_1-1616197233418.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Oscarrdz_0-1616196986428.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F265762i695C46EC64507A00%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Oscarrdz_0-1616196986428.png%22%20alt%3D%22Oscarrdz_0-1616196986428.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EThanks%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2224051%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EIntune%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2278151%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20issues%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2278151%22%20slang%3D%22en-US%22%3Eyou%20could%20try%20to%20add%20a%20try%20%2F%20if%20%2Felse.%3CBR%20%2F%3E%3CBR%20%2F%3EHere%20is%20an%20example.%3CBR%20%2F%3E%3CBR%20%2F%3ETry%20%7B%3CBR%20%2F%3E%24Result%20%3D%20get-winevent%20-FilterHashTable%20%40%7BLogName%3D%22Application%22%3BStartTime%3D(get-date).Addseconds(-600)%7D%7CWhere-Object%7B(%24_.id%20-eq%200)%20-and%20(%24_.message%20-like%20%22*added%20to%20the%20Administrators%20group*%22)%7D%20%7C%20ft%20message%3CBR%20%2F%3E%24ID%20%3D%20%24Result%20%7C%20measure-Object%3CBR%20%2F%3EIf%20(%24ID.Count%20-lt%205)%3CBR%20%2F%3E%7B%3CBR%20%2F%3EWrite-Output%20%22No%20users%20added%20to%20the%20local%20admin%20group%22%3CBR%20%2F%3EExit%200%3CBR%20%2F%3E%7D%3CBR%20%2F%3EElse%3CBR%20%2F%3E%7B%3CBR%20%2F%3EWrite-Output%20%24result%3CBR%20%2F%3EExit%201001%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3Ecatch%3CBR%20%2F%3E%7B%3CBR%20%2F%3EWrite-Warning%20%22Value%20Missing%22%3CBR%20%2F%3EExit%201001%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

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
}