Forum Discussion
Oscarrdz
Mar 19, 2021Copper Contributor
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 per...
Apr 19, 2021
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
}
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
}