Home
%3CLINGO-SUB%20id%3D%22lingo-sub-362899%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-362899%22%20slang%3D%22en-US%22%3E%3CP%3EPerfect..%20Thanks%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F138020%22%20target%3D%22_blank%22%3E%40Haim%20Goldshtein%3C%2FA%3E...%20One%20last%20question%20as%20I%20was%20going%20through%20all%20the%20ms%20docs%20on%20api's.%26nbsp%3B%20We%20came%20across%20%3CA%20href%3D%22https%3A%2F%2Fwdatp-alertexporter-us.windows.com%2Fapi%2Falerts%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwdatp-alertexporter-us.windows.com%2Fapi%2Falerts%3C%2FA%3E%26nbsp%3Band%20when%20we%20try%20to%20call%20it%20we.%26nbsp%3B%20I'm%20assuming%20this%20link%20isn't%20valid%20anymore%3F%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23ff0000%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3EAuthorization%20has%20been%20denied%20for%20this%20request%20%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-361091%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-361091%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F295658%22%20target%3D%22_blank%22%3E%40tferrara%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20you%20probably%20saw%2C%20the%20alert%20includes%20only%20machine%20id%20and%20if%20you%20want%20to%20enrich%20that%20data%20with%20machine%20name%20you%20need%20to%20call%20another%20API%20method%26nbsp%3B%3CA%20title%3D%22Get%20machine%20by%20ID%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fsecurity%2Fthreat-protection%2Fwindows-defender-atp%2Fget-machine-by-id-windows-defender-advanced-threat-protection-new%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGet%20machine%20by%20ID%3C%2FA%3E%26nbsp%3B%20%26nbsp%3Bwhich%20returns%20lots%20of%20information%20about%20the%20machine.%3C%2FP%3E%0A%3CP%3Eyou%20can%20see%20in%20our%20second%20blog%26nbsp%3B%3CA%20title%3D%22Ticketing%20system%20integration%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FWindows-Defender-ATP%2FTicketing-system-integration-Alert-update-API%2Fba-p%2F352191%22%20target%3D%22_self%22%3ETicketing%20system%20integration%3C%2FA%3E%26nbsp%3Bhow%20we%20pull%20alerts%20and%20iterate%20through%20the%20alerts%20to%20use%20the%20alert%20id%20to%20update%20the%20ticketing%20system.%20you%20can%20use%20the%20same%20logic%20to%20get%20the%20machine%20information%20and%20enrich%20the%20alert.%20your%20script%20can%20look%20like%3A%3C%2FP%3E%0A%3CPRE%3E%23%20Returns%20Alerts%20created%20in%20the%20past%204%20hours.%0A%23%20Setting%20a%20place%20holder%20for%20a%20code%20to%20open%20a%20ticket%20in%20external%20ticketing%20system.%0A%0A%24token%20%3D%20.%5CGet-Token.ps1%0A%0A%24dateTime%20%3D%20(Get-Date).ToUniversalTime().AddHours(-400).ToString(%22o%22)%0A%0A%0A%24url%20%3D%20%22https%3A%2F%2Fapi.securitycenter.windows.com%2Fapi%2Falerts%3F%60%24filter%3DalertCreationTime%20ge%20%24dateTime%22%0A%0A%24headers%20%3D%20%40%7B%20%0A%20%20%20%20'Content-Type'%20%3D%20'application%2Fjson'%0A%20%20%20%20Accept%20%3D%20'application%2Fjson'%0A%20%20%20%20Authorization%20%3D%20%22Bearer%20%24token%22%20%0A%7D%0A%0A%24response%20%3D%20Invoke-RestMethod%20-Method%20Get%20-Uri%20%24url%20-Headers%20%24headers%20-ErrorAction%20Stop%0A%0A%23foreach%20alert%2C%20get%20the%20machineId%20and%20alertId%20and%20isloate%20machine%20while%20writing%20the%20alert%20ID%20in%20the%20isolation%20comments.%20%0A%0Aforeach%20(%24alert%20in%20%24response.value)%0A%7B%20%0A%20%20%20%20%24alertId%20%3D%20%24alert.id%0A%20%24machineId%20%3D%20%24alert.machineId%0A%20%0A%20%24url%20%3D%20%22https%3A%2F%2Fapi.securitycenter.windows.com%2Fapi%2Fmachines%2F%24machineId%22%20%0A%20%0A%20%24body%20%3D%20%40%7B%7D%0A%0A%20%24headers%20%3D%20%40%7B%20%20%0A%20%20Authorization%20%3D%20%22Bearer%20%24token%22%20%0A%20%7D%20%0A%20%0A%20%24machineInfoResponse%20%3D%20Invoke-WebRequest%20-Method%20Get%20-Uri%20%24url%20-Body%20%24body%20-Headers%20%24headers%20-ErrorAction%20Stop%20%0A%20%0A%20%23check%20the%20isolatino%20request%20code%20and%20write%20to%20log%20file.%20%0A%20if(%24machineInfoResponse.StatusCode%20-eq%20200)%20%7B%20%0A%20%20%20%20%20%20%20%20%24machineInfo%20%3D%20%20%24machineInfoResponse%20%7C%20select%20-Expand%20Content%20%7C%20ConvertFrom-Json%0A%20%20%20%20%20%20%20%20%24machineName%20%3D%20%24machineInfo.computerDnsName%0A%0A%20%20%23%20replace%20the%20next%20line%20with%20your%20code%20to%20take%20the%20alerts%20data%20and%20enrich%20it%20with%20machine%20info.%0A%20%20%20%20%20%20%20%20%5BSystem.Windows.MessageBox%5D%3A%3AShow(%22Alert%20ID%20-%20%24alertId.%20MachineName%20-%20%24machineName%22)%0A%20%7D%20%0A%20else%20%7B%20%0A%20%20%5BSystem.Windows.MessageBox%5D%3A%3AShow(%22Failed%20to%20get%20machine%20info%20for%20machien%20id%20-%20%24machineId%22)%0A%20%7D%20%0A%7D%3C%2FPRE%3E%0A%3CP%3EWe%20are%20working%20on%20a%26nbsp%3BPowershell%26nbsp%3Bmodule%20which%20should%20ease%20the%20use%20of%20the%20API%20from%20Powershell.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20reply%20if%20the%20answer%20answers%20your%20issue.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-360682%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-360682%22%20slang%3D%22en-US%22%3E%3CP%3EWe'll%20sort%20this%20out%20with%20you%20in%20the%20private%20channel%20and%20publish%20insights%20here%20if%20applicable.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-360576%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-360576%22%20slang%3D%22en-US%22%3E%3CP%3EI%20was%20able%20to%20execute%20everything%20with%20no%20issues%20but%20when%20the%20results%20come%20back%20they%20are%20missing%20the%20machine%20name%20and%20the%20user%20name%20associated%20with%20the%20alert.%26nbsp%3B%20The%20results%20return%20the%20machine%20id%20but%20we%20are%26nbsp%3Bnot%20sure%20how%20to%20get%20that%20converted%20to%20machine%20name.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-360126%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-360126%22%20slang%3D%22en-US%22%3E%3CP%3ETo%20assist%20we%20need%20more%20details.%3C%2FP%3E%0A%3CP%3EWe'll%20contact%20you.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-358500%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-358500%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20able%20to%20view%20everything%20in%20the%20portal.%20I'm%20still%20getting%20unauthorized%20when%20I%20execute%20the%20script.%20I%20gave%20my%20application%20all%20possible%20permissions%20to%20the%20defender%20api.%20I'll%20probably%20just%20open%20a%20ticket%20with%20MS.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-357971%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-357971%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%20one%20of%20the%20troubleshooting%20steps%20I%20was%20asked%20to%20do%20first%20was%20to%20validate%20my%20ATP%20via%20this%20page%20here%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eto%20%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fsecuritycenter.windows.com%252Fpreferences2%252Fintegration%26amp%3Bdata%3D02%257C01%257CHaim.Goldshtein%2540microsoft.com%257Cb173347fa0c7489030be08d69a6812a0%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C636866169123745728%26amp%3Bsdata%3Dqqbfoxmk3H%252BMeuuhqQqlaxH0mcko%252Fs4ERK1UrDHSTKI%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsecuritycenter.windows.com%2Fpreferences2%2Fintegration%3C%2FA%3E%26nbsp%3B%20This%20will%20validate%20your%20ATP%20license%20is%20good%20and%20you%20have%20the%20necessary%20access%20to%20run%20the%20script.%26nbsp%3B%20I%20did%20not%20as%20I%20do%20not%20have%20an%20E5%20or%20M365%20license%20with%20ATP%20enabled.%26nbsp%3B%20If%20you%20get%20the%20following%20graphic%20then%20I%20would%20investigate%20w%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-right%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F84604iA580C599BB73A00B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22NOAtp.jpg%22%20title%3D%22NOAtp.jpg%22%20%2F%3E%3C%2FSPAN%3Eith%20your%20licensing%20team%20.%26nbsp%3B%20Let%20me%20know%20how%20you%20make%20out!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-357944%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-357944%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20getting%20the%20same%20unauthorized%20message.%20If%20the%20application%20is%20the%20one%20obtaining%20the%20token%20that%20give%20you%20access%20to%20the%20API%20then%20how%20do%20you%20apply%20a%20license%20to%20that%20application%3F%20I%20have%20all%20appropriate%20licenses%20assigned%20to%20my%20admin%20account%2C%20and%20I%20still%20get%20the%20unauthorized%20message.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-355951%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-355951%22%20slang%3D%22en-US%22%3E%3CP%3EGreat%20update%20and%20realization%20for%20me%20-%20seems%20counter%20intuitive%20for%20me%20to%20say%20this%2C%20but%20you%20obviously%20(or%20not%20so%20to%20me!)%20need%20to%20be%20licensed%20for%20ATP%20via%20M365%20license%20prior%20to%20running%20the%20code%2C%20If%20you%20have%20a%20M365%20E5%20license%20or%20have%20ATP%20licenced%20you%20can%20run%20the%20code%2C%20or%20alternatively%20you%20can%20license%20ATP%20for%20a%20trial%2C%20here%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fwindowsforbusiness%2Fwindows-atp%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fwindowsforbusiness%2Fwindows-atp%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWithout%20being%20licensed%20for%20ATP%20you%20will%20not%20be%20authorized%20to%20run%20the%20demonstration!%3C%2FP%3E%3CP%3EThanks%20and%20keep%20the%20posts%20coming%20-%20its%20time%20to%20license%20up%20some%20features%20to%20see%20all%20the%20great%20features%3C%2FP%3E%3CP%3EMurray%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353994%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353994%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-right%22%20style%3D%22width%3A%20849px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83709iCC2171432C015589%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22AzureADAppTroubleshooting.jpg%22%20title%3D%22AzureADAppTroubleshooting.jpg%22%20%2F%3E%3C%2FSPAN%3EYes%2C%20the%20article%20made%20that%20clear%20so%20I%20even%20when%20down%20to%20the%20command%20line%20and%20ran%20the%20commands.%26nbsp%3B%20The%20token%20is%20getting%20generated%2C%20its%20the%20web%20response%20that%20is%20being%20tagged%20as%20unauth%20-%20I%20looked%20at%20the%20token%20and%20it%20looks%20fine.%26nbsp%3B%20Its%20why%20I%20was%20asking%20about%20the%20AAD%20License%20required..%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20you%20help%20and%20responses%20on%20this%20matter%20-%20I%20understand%20this%20is%20just%20a%20training%20item%20and%20shouldn't%20be%20so%20hard%20to%20run%20-%20so%20the%20overall%20importance%20isn't%20great%20%2C%20just%20trying%20to%20figure%20out%20why%20its%20not%20working%20has%20me%20digging!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353977%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353977%22%20slang%3D%22en-US%22%3E%3CP%3Eaccording%20to%20the%20token%20validation%20result%20you%20published%2C%20you%20don't%20have%20any%20problem%20with%20the%20permission.%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ecould%20you%20make%20sure%20that%20you%20are%20running%20the%20script%20while%20the%20powershell%20console%20running%20directory%20point%20to%20the%20folder%20with%20the%20scripts%3F%3C%2FP%3E%0A%3CP%3Efor%20example%2C%20if%20you%20saved%20the%20scripts%20under%20C%3A%5Ctemp%5Capi%20then%20you%20need%20to%20make%20sure%20to%20change%20the%20directory%20in%20the%20powershell_ise%20running%20folder%20(you%20can%20use%20the%20dir%20command%20to%20check%20if%20you%20see%20the%20scripts)%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20759px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83700i7D5FBBA72AD8B755%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22powershell.png%22%20title%3D%22powershell.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eif%20you%20run%20the%20script%20from%20another%20folder%20the%20Get-Alert.ps1%20script%20will%20not%20find%20the%20Get-Token.ps1%20script%20and%20you%20will%20get%20an%20error%20message%20401%20(unauthorized)%20like%20you%20published%20in%20your%20first%20message.%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83704i1ADB2AC5745DDE44%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22powershell.png%22%20title%3D%22powershell.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EHope%20it%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353956%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353956%22%20slang%3D%22en-US%22%3E%3CP%3EI%20went%20back%20in%20a%20validated%20my%20steps%2C%20I%20took%20a%20screen%20shot%2C%20and%20confirmed%20I%20am%20in%20the%20right%20directory%20when%20running%20the%20script%2C%20the%20token%20looks%20ok%2C%20-%20What%20license%20for%20Azure%20AD%20do%20I%20need%20to%20get%20the%20logging%3F%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-right%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83697i749C5CB0E3D63DE0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22AzureADApp.jpg%22%20title%3D%22AzureADApp.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353854%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353854%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Murray%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eit%20looks%20like%20your%20token%20holds%20the%20right%20permission.%3C%2FP%3E%0A%3CP%3Efirst%2C%20please%20pay%20attention%20that%20you%20save%20both%20the%20Get-token.ps1%20and%20Get-Alert.ps1%20in%20the%20same%20folder.%3C%2FP%3E%0A%3CP%3Ewhen%20you%20open%20the%20script%20with%20Powershell_ise.exe%20the%20default%20folder%20is%20the%20user%20folder%20(PS%20C%3A%5CUsers%5C%7BUsername%7D%26gt%3B)%20which%20means%20that%20if%20you%20run%20the%20script%20by%20pressing%20F5%20the%20Powershell%20executer%20will%20try%20to%20find%20the%20file%20Get-Token.ps1%20under%20your%20user%20profile.%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eyou%20need%20to%20change%20the%20running%20directory%20to%20the%20directory%20you%20saved%20the%20scripts%20or%20to%20call%20Get-Token.ps1%20script%20by%20using%20its%20full%20path%20and%20not%20the%20relative%20path.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHope%20it%20helps.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353613%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353613%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3E%3CBR%20%2F%3EFrom%20first%20look%2C%20it%20seems%20that%20the%20part%20of%20granting%20permissions%20was%20not%20completed%20successfully.%20Please%20jump%20to%20the%20line%20%22In%20this%20example%2C%20we%20only%20need%20the%20%E2%80%9CRead%20all%20alerts%E2%80%9D%20permission.%22%20and%20try%20to%20follow%20the%20steps%20there.%20If%20you%20find%20that%20the%20desired%20read%20permission%20is%20missing%2C%20that%20might%20be%20the%20problem.%20Please%2C%20pay%20attention%20to%20the%20%22grant%20permissions%22%20step.%3CBR%20%2F%3E%3CBR%20%2F%3EHope%20this%20helps.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353561%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353561%22%20slang%3D%22en-US%22%3E%3CP%3EI%20get%20this%20back%20in%20the%20Token%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20%22roles%22%3A%20%5B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22Alert.Read.All%22%3CBR%20%2F%3E%26nbsp%3B%20%5D%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ebut%20this%20from%20the%20Invoke%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CFONT%20color%3D%22%23000018%22%20face%3D%22monospace%22%3EInvoke-WebRequest%20%3A%20The%20remote%20server%20returned%20an%20error%3A%20(401)%20Unauthorized.%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CFONT%20color%3D%22%23000018%22%20face%3D%22monospace%22%3EDid%20I%20copy%20the%20pwd%20key%20wrong%2C%20I%20was%20sure%20I%20didn't...%20Thoughts%20Ideas%3F%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-330120%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-330120%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20your%20feedback.%3C%2FP%3E%0A%3CP%3EHappy%20to%20hear%20that%20you%20are%20using%20the%20%22Defender%22%20module.%20The%20%22Defender%22%20module%20covers%20the%20AV%20management.%20Here%2C%20in%20this%20blog%20post%2C%20we%20are%20taking%20the%20first%20step%20in%20encouraging%20our%20customers%20to%20try%20and%20automate%20WDATP%20procedures.%20Will%20be%20great%20to%20get%20feedback%20about%20that%20too.%20We%20are%20here%20for%20your%20questions%20and%20feedback.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-328811%22%20slang%3D%22en-US%22%3ERe%3A%20WDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-328811%22%20slang%3D%22en-US%22%3EThis%20maybe%20naive%20since%20I%20don't%20remote%2C%20but%20I%20never%20saw%20anything%2C%20as%20I%20scrolled%20through%2C%20about%20the%20%22Defender%22%20Module.%20It%20is%20a%20great%20Module%20and%20I%20believe%20it%20can%20be%20used%20remotely%20or%20at%20the%20vary%20least%20on%20a%20providing%20server%20in%20a%20small%20operation%3F%3CBR%20%2F%3E%3CBR%20%2F%3EI%20us%20it%20all%20the%20time%20from%20Powershell%20ISE.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-326813%22%20slang%3D%22en-US%22%3EWDATP%20API%20%E2%80%9CHello%20World%E2%80%9D%20(or%20using%20a%20simple%20PowerShell%20script%20to%20pull%20alerts%20via%20WDATP%20APIs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-326813%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%2048px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83411i676D9EBFED18F1AA%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%205%20Minutes%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%2052px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83412iF0578A9CAA1028F8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%26nbsp%3BLow%20complexity%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EApplying%20a%20security%20solution%20in%20an%20enterprise%20environment%20can%20be%20a%20complex%20endeavor.%20Customers%20deploy%20various%20layers%20of%20protection%20solutions%2C%20investigation%20platforms%20and%20hunting%20tools.%20Security%20Operation%20teams%20attempt%20to%20tackle%20this%20task%2C%20but%20typically%20lack%20expensive%20and%20experienced%20human%20resources%20to%20overcome%20this%20challenge.%20Automation%20is%20a%20decent%20mitigation%20but%20automating%20the%20security%20procedures%20and%20wiring%20the%20security%20components%20all%20together%20to%20a%20solid%20cyber%20security%20solution%2C%20requires%20programmatic%20access%20to%20each%20solution.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20these%20series%20of%20blogs%2C%20we%20will%20walk%20you%20through%20common%20automation%20scenarios%20that%20you%20can%20achieve%20with%20Windows%20Defender%20ATP%20to%20optimize%20workflows.%20For%20more%20information%20on%20Windows%20Defender%20ATP%20APIs%2C%20see%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fsecurity%2Fthreat-protection%2Fwindows-defender-atp%2Fuse-apis%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethe%20full%20documentation%3C%2FA%3E%3C%2FSPAN%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20called%20this%20blog%20%E2%80%9CHello%20World%E2%80%9D%20as%20every%20long%20software%20journey%20starts%20with%20a%20simple%20step.%20We%E2%80%99ll%20show%20you%20how%20to%20programmatically%20extract%20Windows%20Defender%20ATP%20alerts%20with%20a%20PowerShell%20script.%20You%20can%20schedule%20this%20script%20to%20run%20on%20any%20machine%20and%20you%20may%20modify%20it%20to%20use%20the%20alert%20information%20in%20your%20specific%20use%20case.%20We%20can%20imagine%20a%20handful%20of%20standard%20use%20cases%20where%20a%20Security%20Operations%20Center%20(SOC)%20can%20leverage%20this%20basic%20capability.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESome%20scenarios%20where%20this%20can%20be%20applied%20include%20use%20with%20security%20information%20and%20event%20management%20(SIEM)%20connectors%2C%20ticketing%20systems%2C%20and%20security%20orchestration%20and%20response%20(SOAR)%20solutions.%20SIEM%20connectors%20may%20be%20the%20simplest%20example%20while%20ticketing%20systems%20are%20a%20common%20one%2C%20and%20SOAR%20solutions%20may%20be%20a%20complex%20use%20case.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1704611047%22%20id%3D%22toc-hId-1704611047%22%3ESo%20let%20gets%20started%E2%80%A6.%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--847545914%22%20id%3D%22toc-hId--847545914%22%3EHow%20long%20it%20takes%20to%20go%20through%20this%20example%3F%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20only%20takes%205%20minutes%20done%20in%20two%20steps%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EApplication%20registration%3A%20takes%202%20minutes%3C%2FLI%3E%0A%3CLI%3EUse%20examples%3A%20only%20requires%20copy%2Fpaste%20of%20a%20short%20PowerShell%20script%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId-895264421%22%20id%3D%22toc-hId-895264421%22%3EDo%20I%20need%20permission%20to%20connect%3F%3C%2FH2%3E%0A%3CP%3EFor%20the%20app%20registration%20stage%2C%20you%20must%20have%20a%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fusers-groups-roles%2Fdirectory-assign-admin-roles%23company-administrator%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGlobal%20administrator%20role%3C%2FA%3E%3C%2FSPAN%3E%20in%20your%20Azure%20Active%20Directory%20(Azure%20AD)%20tenant.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3EStep%201%20-%20Register%20the%20app%20in%20Azure%20Active%20Directory%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWith%20your%20Global%20administrator%20credentials%2C%20login%20to%20the%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fportal.azure.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20portal%3C%2FA%3E.%3C%2FSPAN%3E%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EAzure%20Active%20Directory%20%26gt%3B%20App%20registrations%20%26gt%3B%20New%20registration.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122706i407012BAC7490686%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22registration%201.png%22%20title%3D%22registration%201.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIn%20the%20registration%20form%3A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EName%3C%2FSTRONG%3E-%26nbsp%3BName%20your%20application.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ESupported%20account%20type%3C%2FSTRONG%3E%E2%80%93%20leave%20the%20default%20setting.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ER%3C%2FSTRONG%3E%3CSTRONG%3Eedirect%20Uri%3C%2FSTRONG%3E%E2%80%93%20leave%20empty.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20717px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122704i7655F8EB5A126D71%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22registration%202.png%22%20title%3D%22registration%202.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EClick%20%3CSTRONG%3ERegister%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThe%20application%20I%20created%20is%20the%20authentication%20entity%2C%20just%20like%20a%20service%20account.%20I%20now%20need%20to%20set%20permissions%20to%20my%20app%20and%20save%20its%20credential%20for%20later%20use.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EOn%20your%20new%20application%20page%2C%20click%3CSTRONG%3EAPI%20Permissions%26nbsp%3B%26gt%3B%26nbsp%3BAdd%20permission%3C%2FSTRONG%3E%26nbsp%3B%26gt%3B%26nbsp%3B%3CSTRONG%3EAPIs%20my%20organization%20uses%3C%2FSTRONG%3E%26nbsp%3B%26gt%3B%20type%26nbsp%3B%3CSTRONG%3EWindowsDefenderATP%26nbsp%3B%3C%2FSTRONG%3Eand%20click%20on%26nbsp%3B%3CSTRONG%3EWindowsDefenderATP%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%20style%3D%22list-style-type%3A%20none%3B%22%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%3C%2FSTRONG%3E%3A%20WindowsDefenderATP%20does%20not%20appear%20in%20the%20original%20list.%20You%20need%20to%20start%20writing%20its%20name%20in%20the%20text%20box%20to%20see%20it%20appear%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122707i0BDE40F07852D229%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22registration%203.png%22%20title%3D%22registration%203.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EChoose%26nbsp%3B%3CSTRONG%3EApplication%20permissions%3C%2FSTRONG%3E%26nbsp%3B%26gt%3B%26nbsp%3B%3CSTRONG%3EAlert.Read.All%3C%2FSTRONG%3E%26nbsp%3B%26gt%3B%20Click%20on%26nbsp%3B%3CSTRONG%3EAdd%20permissions%3C%2FSTRONG%3E%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20721px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122705iD3DFE3789ED027AF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22registration%204.png%22%20title%3D%22registration%204.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EAfter%20clicking%20the%20%3CSTRONG%3EAdd%20Permissions%20%3C%2FSTRONG%3Ebutton%2C%20on%20the%20next%20screen%20we%20need%20to%20grant%20consent%20for%20the%20permission%20to%20take%20effect.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122709i56771F44ED5E5C61%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22registration%205.png%22%20title%3D%22registration%205.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EPress%20the%20%22Grant%20admin%20consent%20for%20%7Byour%20tenant%20name%7D%22%20button.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EAs%20explained%2C%20the%20registered%20app%20is%20an%20authentication%20entity%20with%20permission%20to%20access%20all%20alerts%20for%20reading.%20Now%20I%20need%20to%20get%20and%20store%20the%20authentication%20and%20authorization%20credentials%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EKey%20(application%20secret)%2C%20Application%20ID%2C%20and%20Tenant%20ID%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThink%20of%20your%20secret%20like%20a%20%3CSTRONG%3Epassword%3C%2FSTRONG%3E%2C%20Application%20ID%20as%20%3CSTRONG%3Eusername%3C%2FSTRONG%3Eand%20Tenant%20ID%20as%20a%20%3CSTRONG%3Edomain%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ETo%20get%20credentials%3A%3CUL%3E%0A%3CLI%3EIn%20your%20application%20page%2C%20Click%3CSTRONG%3ECertificate%20%26amp%3B%20Secrets%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESpecify%20a%20key%20description%20and%20set%20an%20expiration%20for%201%20year.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20714px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122708iCB1B4F5E7F806913%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22secret%201.png%22%20title%3D%22secret%201.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EClick%20Add.%3C%2FLI%3E%0A%3CLI%3EThe%20application%20key%20will%20appear.%20%3CBR%20%2F%3EIMPORTANT%3A%20%3CSTRONG%3ECopy%20and%20store%20this%20key%20in%20a%20safe%20place.%20Treat%20it%20like%20a%20password.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EGet%20your%20%3CSTRONG%3Eapplication%20ID%3C%2FSTRONG%3Eand%20your%20%3CSTRONG%3Etenant%20ID%3C%2FSTRONG%3E%3A%3CUL%3E%0A%3CLI%3EOn%20your%20application%20page%2C%20go%20to%26nbsp%3B%3CSTRONG%3EOverview%26nbsp%3B%3C%2FSTRONG%3Eand%20copy%20the%20following%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20883px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122710iDF4396671C483E75%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22secret%202.png%22%20title%3D%22secret%202.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3CSTRONG%3EDone!%20%3C%2FSTRONG%3EYou%20have%20successfully%20registered%20an%20application.%20You%20may%20reuse%20this%20application%20when%20going%20through%20the%20exercises%20that%20we%E2%80%99ll%20be%20using%20in%20future%20blogs%20and%20experiments.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20we%E2%80%99ll%20need%20to%20connect%20the%20API%20which%20means%20getting%20a%20token.%20The%20token%20is%20proof%20for%20Windows%20Defender%20ATP%20that%20an%20API%20call%20is%20authenticated%20and%20authorized.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3EConnecting%20the%20API%3A%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECopy%20the%20text%20below%20to%20PowerShell%20ISE%20or%20to%20a%20text%20editor.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%23%20That%20code%20get%20the%20App%20Context%20Token%20and%20save%20it%20to%20file%20name%20%22Latest-token.txt%22%20under%20the%20current%20directory%0A%23%20Paste%20below%20your%20Tenant%20ID%2C%20App%20ID%20and%20App%20Secret%20(App%20key).%0A%0A%24tenantId%20%3D%20'f839b112-d9d7-94d27-9bf6-94542403f21c'%20%23%23%23%20Paste%20your%20own%20tenant%20ID%20here%0A%24appId%20%3D%20'94fbf312-ae3f-47f4-8eeb-d375d1299e8f'%20%23%23%23%20Paste%20your%20own%20app%20ID%20here%0A%24appSecret%20%3D%20'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890%3D'%20%23%23%23%20Paste%20your%20own%20app%20keys%20here%0A%0A%24resourceAppIdUri%20%3D%20'https%3A%2F%2Fapi.securitycenter.windows.com'%0A%24oAuthUri%20%3D%20%22https%3A%2F%2Flogin.windows.net%2F%24TenantId%2Foauth2%2Ftoken%22%0A%0A%24authBody%20%3D%20%5BOrdered%5D%20%40%7B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20resource%20%3D%20%22%24resourceAppIdUri%22%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20client_id%20%3D%20%22%24appId%22%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20client_secret%20%3D%20%22%24appSecret%22%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20grant_type%20%3D%20'client_credentials'%0A%7D%0A%0A%24authResponse%20%3D%20Invoke-RestMethod%20-Method%20Post%20-Uri%20%24oAuthUri%20-Body%20%24authBody%20-ErrorAction%20Stop%0A%24token%20%3D%20%24authResponse.access_token%0AOut-File%20-FilePath%20%22.%2FLatest-token.txt%22%20-InputObject%20%24token%0Areturn%20%24token%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ESave%20the%20script%20to%20file.%20You%20can%20name%20it%20%22%3CSTRONG%3EGet-Token.ps1%22.%20%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ERunning%20this%20script%20by%20pressing%20F5%20will%20get%20a%20token%20and%20save%20it%20in%20the%20working%20folder%20under%20the%20name%20%22.%2FLatest-token.txt%22.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CTABLE%20width%3D%22626%22%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22626%22%3E%0A%3CP%3ENote%3A%3C%2FP%3E%0A%3CP%3EIf%20you%20are%20getting%20an%20error%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%5CGet-Token.ps1%20cannot%20be%20loaded%20because%20running%20scripts%20is%20disabled%20on%20this%20system.%20For%20more%20information%2C%20see%20about_Execution_Policies%20at%20https%3A%2Fgo.microsoft.com%2Ffwlink%2F%3FLinkID%3D135170%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3EThat%20error%20indicates%20that%20your%20Powershell%20execution%20policy%20not%20allowing%20you%20to%20run%20scripts.%20You%20can%20change%20the%20execution%20policy%20by%20running%20that%20command%20in%20Powershell%20console%3A%3C%2FP%3E%0A%3CP%3EPS%20c%3A%5C%26gt%3B%26gt%3BSet-ExecutionPolicy%20unrestricted%20-Scope%20CurrentUser%3C%2FP%3E%0A%3CP%3EConsider%20consulting%20with%20your%20system%20administrator%20about%20your%20organization%E2%80%99s%20Powershell%20execution%20policy.%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3E%26nbsp%3B%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3ESanity%20Check%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIn%20your%20browser%20go%20to%3A%3CSPAN%3E%20%3CA%20href%3D%22https%3A%2F%2Fjwt.ms%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fjwt.ms%2F%3C%2FA%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3ECopy%20the%20token%20(the%20content%20of%20the%20Latest-token.txt%20file).%3C%2FLI%3E%0A%3CLI%3EPaste%20in%20the%20top%20box.%3C%2FLI%3E%0A%3CLI%3ELook%20for%20the%20%22roles%22%20section.%20Find%20the%20Alert.Read.All%20role.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ENow%20let%E2%80%99s%20gets%20the%20alerts%2C%20Copy%20the%20following%20text%20to%20a%20new%20PowerShell%20Script.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%23%20Returns%20Alerts%20created%20in%20the%20past%2048%20hours.%0A%24token%20%3D%20.%2FGet-Token.ps1%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CBR%20%2F%3E%23run%20the%20script%20Get-Token.ps1%26nbsp%3B%20-%20make%20sure%20you%20are%20running%20this%20script%20from%20the%20same%20folder%20of%20Get-Token.ps1%0A%23%20Get%20Alert%20from%20the%20last%2048%20hours.%20Make%20sure%20you%20have%20alerts%20in%20that%20time%20frame.%0A%3CBR%20%2F%3E%24dateTime%20%3D%20(Get-Date).ToUniversalTime().AddHours(-48).ToString(%22o%22)%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%0A%0A%23%20The%20URL%20contains%20the%20type%20of%20query%20and%20the%20time%20filter%20we%20create%20above%0A%23%20Read%20more%20about%20other%20query%20options%20and%20filters%20here%0A%24url%20%3D%20%22https%3A%2F%2Fapi.securitycenter.windows.com%2Fapi%2Falerts%3F%60%24filter%3DalertCreationTime%20ge%20%24dateTime%22%0A%0A%23%20Set%20the%20WebRequest%20headers%0A%24headers%20%3D%20%40%7B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20'Content-Type'%20%3D%20'application%2Fjson'%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Accept%20%3D%20'application%2Fjson'%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Authorization%20%3D%20%22Bearer%20%24token%22%0A%7D%0A%3CBR%20%2F%3E%23%20Send%20the%20webrequest%20and%20get%20the%20results.%26nbsp%3B%0A%24response%20%3D%20Invoke-WebRequest%20-Method%20Get%20-Uri%20%24url%20-Headers%20%24headers%20-ErrorAction%20Stop%0A%23Extract%20the%20alerts%20from%20the%20results.%26nbsp%3B%0A%24alerts%20%3D%26nbsp%3B%20(%24response%20%7C%20ConvertFrom-Json).value%20%7C%20ConvertTo-Json%0A%0A%23Get%20string%20with%20the%20execution%20time.%20We%20concatenate%20that%20string%20to%20the%20output%20file%20to%20avoid%20overwrite%20the%20file%0A%24dateTimeForFileName%20%3D%20Get-Date%20-Format%20o%20%7C%20foreach%20%7B%24_%20-replace%20%22%3A%22%2C%20%22.%22%7D%26nbsp%3B%26nbsp%3B%26nbsp%3B%0A%0A%23save%20the%20result%20as%20json%20and%20as%20csv%0A%24outputJsonPath%20%3D%20%22.%2FLatest%20Alerts%20%24dateTimeForFileName.json%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%0A%24outputCsvPath%20%3D%20%22.%2FLatest%20Alerts%20%24dateTimeForFileName.csv%22%0A%3CBR%20%2F%3EOut-File%20-FilePath%20%24outputJsonPath%20-InputObject%20%24alerts%0A(%24alerts%20%7C%20ConvertFrom-Json)%20%7C%20Export-CSV%20%24outputCsvPath%20-NoTypeInformation%0A%0A%3C%2FPRE%3E%0A%3CUL%3E%0A%3CLI%3ESave%20the%20file%20in%20the%20same%20folder%20you%20saved%20the%20previous%20script%20(Get-Token.ps1).%3C%2FLI%3E%0A%3CLI%3EYou%20can%20run%20the%20script%20by%20right-clicking%20on%20the%20file%20and%20choosing%20%22Run%20with%20PowerShell%22%20or%20run%20it%20from%20PowerShell%20console.%3CBR%20%2F%3E%3CSTRONG%3ENOTE%3A%20If%20you%20are%20using%20powershell_ise.exe%20make%20sure%20to%20change%20directory%20to%20the%20directory%20with%20the%20scripts.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EYou%20will%20now%20see%20two%20files%20(json%20and%20csv)%20created%20in%20the%20same%20folder%20as%20the%20scripts.%3C%2FLI%3E%0A%3CLI%3EThe%20files%20are%20the%20latest%20alert%20from%20your%20tenant%20in%20the%20past%2048%20hours.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%E2%80%99re%20all%20done!%20You%20have%20just%20successfully%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECreated%20and%20registered%20and%20application%3C%2FLI%3E%0A%3CLI%3EGranted%20permission%20for%20that%20application%20to%20read%20alerts%3C%2FLI%3E%0A%3CLI%3EConnected%20the%20API%3C%2FLI%3E%0A%3CLI%3EUse%20a%20PowerShell%20script%20to%20return%20alerts%20created%20in%20the%20past%2048%20hours%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EIn%20the%20next%20blog%2C%20we%E2%80%99ll%20walk%20you%20through%20updating%20alert%20status%20programmatically.%20I%20invite%20you%20to%20suggest%20more%20use%20cases%20that%20you%E2%80%99d%20like%20for%20us%20to%20blog%20about%2C%20provide%20feedback%2C%20and%20ask%20questions%20about%20this%20post!%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThanks!%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F138020%22%20target%3D%22_blank%22%3E%40Haim%20Goldshtein%3C%2FA%3E%2C%20security%20software%20engineer%2C%20WDATP%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F183190%22%20target%3D%22_blank%22%3E%40Dan%20Michelson%3C%2FA%3E%2C%20program%20manager%2C%20WDATP%3C%2FP%3E%0A%3CP%3E%40Ben%20Alfasi%2C%26nbsp%3Bsoftware%20engineer%2C%26nbsp%3BWindows%26nbsp%3BDefender%20ATP%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-326813%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%2052px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F83412iF0578A9CAA1028F8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-326813%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Edanmich%40microsoft.com%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EHaim.Goldshtein%40microsoft.com%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

image.png 5 Minutes

image.png Low complexity

 

Applying a security solution in an enterprise environment can be a complex endeavor. Customers deploy various layers of protection solutions, investigation platforms and hunting tools. Security Operation teams attempt to tackle this task, but typically lack expensive and experienced human resources to overcome this challenge. Automation is a decent mitigation but automating the security procedures and wiring the security components all together to a solid cyber security solution, requires programmatic access to each solution.

 

In these series of blogs, we will walk you through common automation scenarios that you can achieve with Windows Defender ATP to optimize workflows. For more information on Windows Defender ATP APIs, see the full documentation.

 

We called this blog “Hello World” as every long software journey starts with a simple step. We’ll show you how to programmatically extract Windows Defender ATP alerts with a PowerShell script. You can schedule this script to run on any machine and you may modify it to use the alert information in your specific use case. We can imagine a handful of standard use cases where a Security Operations Center (SOC) can leverage this basic capability.

 

Some scenarios where this can be applied include use with security information and event management (SIEM) connectors, ticketing systems, and security orchestration and response (SOAR) solutions. SIEM connectors may be the simplest example while ticketing systems are a common one, and SOAR solutions may be a complex use case.

 

So let gets started….

 

How long it takes to go through this example?

 

It only takes 5 minutes done in two steps:

  • Application registration: takes 2 minutes
  • Use examples: only requires copy/paste of a short PowerShell script

Do I need permission to connect?

For the app registration stage, you must have a Global administrator role in your Azure Active Directory (Azure AD) tenant.

 

Step 1 - Register the app in Azure Active Directory

 

  • With your Global administrator credentials, login to the Azure portal.
    • Azure Active Directory > App registrations > New registration.

registration 1.png

 

  • In the registration form:
    • Name - Name your application.
    • Supported account type – leave the default setting.
    • Redirect Uri – leave empty.

registration 2.png

  • Click Register

The application I created is the authentication entity, just like a service account. I now need to set permissions to my app and save its credential for later use.

 

  • On your new application page, click API Permissions > Add permission > APIs my organization uses > type WindowsDefenderATP and click on WindowsDefenderATP
  •  

    Note: WindowsDefenderATP does not appear in the original list. You need to start writing its name in the text box to see it appear

registration 3.png

  • Choose Application permissions > Alert.Read.All > Click on Add permissions:

registration 4.png

  • After clicking the Add Permissions button, on the next screen we need to grant consent for the permission to take effect.

registration 5.png

  • Press the "Grant admin consent for {your tenant name}" button.

As explained, the registered app is an authentication entity with permission to access all alerts for reading. Now I need to get and store the authentication and authorization credentials:

  • Key (application secret), Application ID, and Tenant ID

Think of your secret like a password, Application ID as username and Tenant ID as a domain.

 

  • To get credentials:
    • In your application page, Click Certificate & Secrets
    • Specify a key description and set an expiration for 1 year.

secret 1.png

  • Click Add.
  • The application key will appear.
    IMPORTANT: Copy and store this key in a safe place. Treat it like a password.
  • Get your application ID and your tenant ID:
    • On your application page, go to Overview and copy the following

 secret 2.png

 

 

 Done! You have successfully registered an application. You may reuse this application when going through the exercises that we’ll be using in future blogs and experiments.

 

Now we’ll need to connect the API which means getting a token. The token is proof for Windows Defender ATP that an API call is authenticated and authorized.

 

Connecting the API:

  • Copy the text below to PowerShell ISE or to a text editor.

 

 

# That code get the App Context Token and save it to file name "Latest-token.txt" under the current directory
# Paste below your Tenant ID, App ID and App Secret (App key).

$tenantId = 'f839b112-d9d7-94d27-9bf6-94542403f21c' ### Paste your own tenant ID here
$appId = '94fbf312-ae3f-47f4-8eeb-d375d1299e8f' ### Paste your own app ID here
$appSecret = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890=' ### Paste your own app keys here

$resourceAppIdUri = 'https://api.securitycenter.windows.com'
$oAuthUri = "https://login.windows.net/$TenantId/oauth2/token"

$authBody = [Ordered] @{
    resource = "$resourceAppIdUri"
    client_id = "$appId"
    client_secret = "$appSecret"
    grant_type = 'client_credentials'
}

$authResponse = Invoke-RestMethod -Method Post -Uri $oAuthUri -Body $authBody -ErrorAction Stop
$token = $authResponse.access_token
Out-File -FilePath "./Latest-token.txt" -InputObject $token
return $token

 

 

  • Save the script to file. You can name it "Get-Token.ps1".
  • Running this script by pressing F5 will get a token and save it in the working folder under the name "./Latest-token.txt".

 

Note:

If you are getting an error:

\Get-Token.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

That error indicates that your Powershell execution policy not allowing you to run scripts. You can change the execution policy by running that command in Powershell console:

PS c:\>>Set-ExecutionPolicy unrestricted -Scope CurrentUser

Consider consulting with your system administrator about your organization’s Powershell execution policy.

 

Sanity Check

  • In your browser go to: https://jwt.ms/
  • Copy the token (the content of the Latest-token.txt file).
  • Paste in the top box.
  • Look for the "roles" section. Find the Alert.Read.All role.

 

  • Now let’s gets the alerts, Copy the following text to a new PowerShell Script.

 

# Returns Alerts created in the past 48 hours.
$token = ./Get-Token.ps1       
#run the script Get-Token.ps1  - make sure you are running this script from the same folder of Get-Token.ps1 # Get Alert from the last 48 hours. Make sure you have alerts in that time frame.
$dateTime = (Get-Date).ToUniversalTime().AddHours(-48).ToString("o")       # The URL contains the type of query and the time filter we create above # Read more about other query options and filters here $url = "https://api.securitycenter.windows.com/api/alerts?`$filter=alertCreationTime ge $dateTime" # Set the WebRequest headers $headers = @{     'Content-Type' = 'application/json'     Accept = 'application/json'     Authorization = "Bearer $token" }
# Send the webrequest and get the results.  $response = Invoke-WebRequest -Method Get -Uri $url -Headers $headers -ErrorAction Stop #Extract the alerts from the results.  $alerts =  ($response | ConvertFrom-Json).value | ConvertTo-Json #Get string with the execution time. We concatenate that string to the output file to avoid overwrite the file $dateTimeForFileName = Get-Date -Format o | foreach {$_ -replace ":", "."}    #save the result as json and as csv $outputJsonPath = "./Latest Alerts $dateTimeForFileName.json"     $outputCsvPath = "./Latest Alerts $dateTimeForFileName.csv"
Out-File -FilePath $outputJsonPath -InputObject $alerts ($alerts | ConvertFrom-Json) | Export-CSV $outputCsvPath -NoTypeInformation
  • Save the file in the same folder you saved the previous script (Get-Token.ps1).
  • You can run the script by right-clicking on the file and choosing "Run with PowerShell" or run it from PowerShell console.
    NOTE: If you are using powershell_ise.exe make sure to change directory to the directory with the scripts.

 

  • You will now see two files (json and csv) created in the same folder as the scripts.
  • The files are the latest alert from your tenant in the past 48 hours.

 

You’re all done! You have just successfully:

  • Created and registered and application
  • Granted permission for that application to read alerts
  • Connected the API
  • Use a PowerShell script to return alerts created in the past 48 hours

 

 

In the next blog, we’ll walk you through updating alert status programmatically. I invite you to suggest more use cases that you’d like for us to blog about, provide feedback, and ask questions about this post!

 

Thanks!

@Haim Goldshtein, security software engineer, WDATP

@Dan Michelson, program manager, WDATP

@Ben Alfasi, software engineer, Windows Defender ATP  

17 Comments
This maybe naive since I don't remote, but I never saw anything, as I scrolled through, about the "Defender" Module. It is a great Module and I believe it can be used remotely or at the vary least on a providing server in a small operation?

I us it all the time from Powershell ISE.
Microsoft

Thanks for your feedback.

Happy to hear that you are using the "Defender" module. The "Defender" module covers the AV management. Here, in this blog post, we are taking the first step in encouraging our customers to try and automate WDATP procedures. Will be great to get feedback about that too. We are here for your questions and feedback.

 

Contributor

I get this back in the Token 

  "roles": [
    "Alert.Read.All"
  ],

but this from the Invoke

Invoke-WebRequest : The remote server returned an error: (401) Unauthorized.

Did I copy the pwd key wrong, I was sure I didn't... Thoughts Ideas?

 

 

Microsoft
Hi,

From first look, it seems that the part of granting permissions was not completed successfully. Please jump to the line "In this example, we only need the “Read all alerts” permission." and try to follow the steps there. If you find that the desired read permission is missing, that might be the problem. Please, pay attention to the "grant permissions" step.

Hope this helps.

Microsoft

Hi Murray,

 

it looks like your token holds the right permission.

first, please pay attention that you save both the Get-token.ps1 and Get-Alert.ps1 in the same folder.

when you open the script with Powershell_ise.exe the default folder is the user folder (PS C:\Users\{Username}>) which means that if you run the script by pressing F5 the Powershell executer will try to find the file Get-Token.ps1 under your user profile. 

you need to change the running directory to the directory you saved the scripts or to call Get-Token.ps1 script by using its full path and not the relative path.

 

Hope it helps.

 

Contributor

I went back in a validated my steps, I took a screen shot, and confirmed I am in the right directory when running the script, the token looks ok, - What license for Azure AD do I need to get the logging? AzureADApp.jpg

Microsoft

according to the token validation result you published, you don't have any problem with the permission. 

could you make sure that you are running the script while the powershell console running directory point to the folder with the scripts?

for example, if you saved the scripts under C:\temp\api then you need to make sure to change the directory in the powershell_ise running folder (you can use the dir command to check if you see the scripts) 

 

powershell.png

 

if you run the script from another folder the Get-Alert.ps1 script will not find the Get-Token.ps1 script and you will get an error message 401 (unauthorized) like you published in your first message.


powershell.png

Hope it helps.

Contributor

 

AzureADAppTroubleshooting.jpgYes, the article made that clear so I even when down to the command line and ran the commands.  The token is getting generated, its the web response that is being tagged as unauth - I looked at the token and it looks fine.  Its why I was asking about the AAD License required.. 

Thanks for you help and responses on this matter - I understand this is just a training item and shouldn't be so hard to run - so the overall importance isn't great , just trying to figure out why its not working has me digging!

Contributor

Great update and realization for me - seems counter intuitive for me to say this, but you obviously (or not so to me!) need to be licensed for ATP via M365 license prior to running the code, If you have a M365 E5 license or have ATP licenced you can run the code, or alternatively you can license ATP for a trial, here https://www.microsoft.com/en-us/windowsforbusiness/windows-atp 

Without being licensed for ATP you will not be authorized to run the demonstration!

Thanks and keep the posts coming - its time to license up some features to see all the great features

Murray

Frequent Visitor

I'm getting the same unauthorized message. If the application is the one obtaining the token that give you access to the API then how do you apply a license to that application? I have all appropriate licenses assigned to my admin account, and I still get the unauthorized message.

Contributor

Hello, one of the troubleshooting steps I was asked to do first was to validate my ATP via this page here - 

 

to https://securitycenter.windows.com/preferences2/integration  This will validate your ATP license is good and you have the necessary access to run the script.  I did not as I do not have an E5 or M365 license with ATP enabled.  If you get the following graphic then I would investigate wNOAtp.jpgith your licensing team .  Let me know how you make out!

Frequent Visitor

I'm able to view everything in the portal. I'm still getting unauthorized when I execute the script. I gave my application all possible permissions to the defender api. I'll probably just open a ticket with MS.

Microsoft

To assist we need more details.

We'll contact you.

 

New Contributor

I was able to execute everything with no issues but when the results come back they are missing the machine name and the user name associated with the alert.  The results return the machine id but we are not sure how to get that converted to machine name.

Microsoft

We'll sort this out with you in the private channel and publish insights here if applicable.

Microsoft

Hey @tferrara ,

 

As you probably saw, the alert includes only machine id and if you want to enrich that data with machine name you need to call another API method Get machine by ID   which returns lots of information about the machine.

you can see in our second blog Ticketing system integration how we pull alerts and iterate through the alerts to use the alert id to update the ticketing system. you can use the same logic to get the machine information and enrich the alert. your script can look like:

# Returns Alerts created in the past 4 hours.
# Setting a place holder for a code to open a ticket in external ticketing system.

$token = .\Get-Token.ps1

$dateTime = (Get-Date).ToUniversalTime().AddHours(-400).ToString("o")


$url = "https://api.securitycenter.windows.com/api/alerts?`$filter=alertCreationTime ge $dateTime"

$headers = @{ 
    'Content-Type' = 'application/json'
    Accept = 'application/json'
    Authorization = "Bearer $token" 
}

$response = Invoke-RestMethod -Method Get -Uri $url -Headers $headers -ErrorAction Stop

#foreach alert, get the machineId and alertId and isloate machine while writing the alert ID in the isolation comments. 

foreach ($alert in $response.value)
{ 
    $alertId = $alert.id
	$machineId = $alert.machineId
	
	$url = "https://api.securitycenter.windows.com/api/machines/$machineId" 
	
	$body = @{}

	$headers = @{		
		Authorization = "Bearer $token" 
	} 
	
	$machineInfoResponse = Invoke-WebRequest -Method Get -Uri $url -Body $body -Headers $headers -ErrorAction Stop 
	
	#check the isolatino request code and write to log file. 
	if($machineInfoResponse.StatusCode -eq 200) { 
        $machineInfo =  $machineInfoResponse | select -Expand Content | ConvertFrom-Json
        $machineName = $machineInfo.computerDnsName

		# replace the next line with your code to take the alerts data and enrich it with machine info.
        [System.Windows.MessageBox]::Show("Alert ID - $alertId. MachineName - $machineName")
	} 
	else { 
		[System.Windows.MessageBox]::Show("Failed to get machine info for machien id - $machineId")
	} 
}

We are working on a Powershell module which should ease the use of the API from Powershell.

 

Please reply if the answer answers your issue.

 

New Contributor

Perfect.. Thanks @Haim Goldshtein... One last question as I was going through all the ms docs on api's.  We came across https://wdatp-alertexporter-us.windows.com/api/alerts and when we try to call it we.  I'm assuming this link isn't valid anymore?

Authorization has been denied for this request