Forum Discussion

Oscarrdz's avatar
Oscarrdz
Copper Contributor
Mar 19, 2021

Powershell script issues

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!

 

 

Thanks 

 

  • 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
    }

Resources