A
A
Alexander Pavlov2021-12-22 10:37:28
PowerShell
Alexander Pavlov, 2021-12-22 10:37:28

How to output values ​​from an array without curly braces in Powershell?

Hello.

There is a script that displays the names of the containers in the organizational unit.

spoiler

$ounit = Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase "OU=example,DC=example,DC=local" -SearchScope Subtree | Where {
    $_.Name -notlike "Bank" -and 
    $_.Name -notlike "aux" -and
    $_.Name -notlike "SharePoint" -and
    $_.Name -notlike "disabled" -and
    $_.Name -notlike "old" -and
    $_.Name -notlike "operc" -and
    $_.Name -notlike "External" -and
    $_.Name -notlike "Scan" -and
    $_.Name -notlike "dad" 
} | select Name | sort Name


for ($i = 0; $i -lt $ounit.Count; $i++) {
    $a = "$i {0}" -f $ounit[$i]
    $a
}

$ar = Read-Host "Enter"

for ($i = 0; $i -lt $ounit.Count; $i++) {
    $a = "$i {0}" -f $ounit[$i]
    if ($ar -match $i) {
        $r = $ounit[$i] 
    }
}

$r.Name



Works great as it should, but outputs data

0 @{Name=Administration}

How do I get rid of the curly braces so that it prints 0 Administration?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew AT, 2021-12-22
@Sanchez9891

for ($i = 0; $i -lt $ounit.Count; $i++) {
    $a = "$i {0}" -f $ounit[$i].Name
    $a
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question