簡體   English   中英

Azure DevOps - PowerShell Output 作為文件

[英]Azure DevOps - PowerShell Output as File

我在 Azure DevOps 中編寫了 PowerShell 腳本,以將所有 Azure Active Directory 用戶作為 JSONM。 我想將 output 保存為 Azure 存儲庫中的 JSON 文件。

我的代碼:

Install-Module -Name "AzureAD" -Force
Import-Module -Name "AzureAD"
[string]$userName = 'TEST@TEST.TEST'
[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

這是一個例子:

YOUR-COMMAND | Out-File -FilePath c:\PATH\TO\FOLDER\OUTPUT.txt

您對此似乎是對的,您是否嘗試過先在 txt 中查看它給您的信息? 或者它根本不保存文件?

嗯......你能舉一個json的例子嗎? 默認情況下,“ConvertTo-Json”中的深度為 2。因此您可能必須像這樣更改它:

Get-AzureADUser | select @{N='email';E={$_.UserPrincipalName}} | ConvertTo-Json -depth 100 | Out-File -FilePath .\UserExport.txt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM