Home > Mobile >  Azure DevOps - PowerShell Output as File
Azure DevOps - PowerShell Output as File

Time:02-03

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

CodePudding user response:

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 ?

CodePudding user response:

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
  •  Tags:  
  • Related