Answer the question
In order to leave comments, you need to log in
How to add your object to the PowerShell array?
Good afternoon. I'm just getting started in powershell and have a task like this.
You need to create your own object with your own parameters. And as information arrives from the cycle below, fill it with the necessary values.
I understand that to create an object, you need to write something like this:
#создаем параметры, которые принимает объек
$testProps = @{
Name = (Get-AzureRmSubscription)[0].Name
State = (Get-AzureRmSubscription)[0].State
Id = (Get-AzureRmSubscription)[0].Id
}
$testObj = New-Object -TypeName PSObject -Property $testProps #создаем объект с нужными параметрами
$allSubscriptions = Get-AzureRmSubscription
for ($i = 0; $i -lt $allSubscriptions.Length; $i++) {
Select-AzureRmSubscription -SubscriptionName $allSubscriptions[$i].Name
Write-Output "--->>> Subscr - " $allSubscriptions[$i].Name
$allResourseGroup = Get-AzureRmResourceGroup
for ($y = 0; $y -lt $allResourseGroup.Length; $y++) {
Write-Output "-->> RG - " $allResourseGroup[$y].ResourceGroupName
$arrRecServVault = Get-AzureRmRecoveryServicesVault -ResourceGroupName $allResourseGroup[$y].ResourceGroupName
Out-File -FilePath D:\555\test.txt -InputObject $arrRecServVault
}
}
Answer the question
In order to leave comments, you need to log in
Here is a good article on this topic .
You just need to create an object and do nothing, it will automatically fall into the pipeline
. Then it can be displayed on the grid
Or save to an array
$a = 1..10 | %{ [PSCustomObject]@{ Name="Name_$_"; Value = $_} }
$a
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question