Reputation: 67
I have written a PowerShell script in Azure DevOps to get all Azure Active Directory users as JSONM. I want to save the output as a JSON file in Azure repos.
My code:
Install-Module -Name "AzureAD" -Force
Import-Module -Name "AzureAD"
[string]$userName = '[email protected]'
[string]$userPassword = 'TEST'
[securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force
[pscredential]$credObject = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword)
Connect-AzureAD -Credential $credObject
Get-AzureADUser | select @{N='email';E={$_.UserPrincipalName}} | ConvertTo-Json | Out-File -FilePath .\UserExport.txt
Upvotes: 0
Views: 1558
Reputation: 131
Hm... Can you give an example of the json ? By default the depth in "ConvertTo-Json" is 2. So you may have to change it like this :
Get-AzureADUser | select @{N='email';E={$_.UserPrincipalName}} | ConvertTo-Json -depth 100 | Out-File -FilePath .\UserExport.txt
Upvotes: 1
Reputation: 131
here is an example :
YOUR-COMMAND | Out-File -FilePath c:\PATH\TO\FOLDER\OUTPUT.txt
You seemed right to this, have you tried to see what it gives you in txt first ? Or it simply don't save the file ?
Upvotes: 2