va007
March 3, 2019, 11:03am
1
Can someone please tell me how to mock Invoke-RestMethod and Get-AzureADUser. Thanks in Advance.
$userprincipalName = (Get-AzureADUser -Filter "DisplayName eq '$($Owner)' and UserType eq 'Member'").UserPrincipalName
$samAccountName = Invoke-RestMethod -Method Get -Headers @{
Authorization=$token.CreateAuthorizationHeader()
'Content-Type'="application/json"
} -Uri ("https://graph.microsoft.com/v1.0/users/$($userprincipalName)/mailNickname") |
select -expand Value
This is what Pester is for.
Get started with Pester (PowerShell unit testing framework)
Summary: Guest blogger, Dave Wyatt introduces a new test framework for PowerShell called Pester. This week we are honored to have one of the authors of Pester here with us on the Hey, Scripting Guys! Blog. It’s Dave Wyatt himself, a Cloud and...
Are you saying, you’ve tried to use the above tool and not proven successful for your use case / needs?
Or that you could not derive a way you felt prudent with it?
Ensure you are doing some error handling as well.
Example:
Error Handling for Invoke-RestMethod - PowerShell
https://stackoverflow.com/questions/29613572/error-handling-for-invoke-restmethod-powershell