V
V
Vyacheslav Stepko2018-07-17 18:00:59
PowerShell
Vyacheslav Stepko, 2018-07-17 18:00:59

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 #создаем объект с нужными параметрами

How can I create an object that will have many Name, State and Id values, roughly speaking a table?
What do I need to add to the script below to collect this information.
$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

1 answer(s)
A
ApeCoder, 2018-07-17
@slavapride

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 question

Ask a Question

731 491 924 answers to any question