OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Using hash table via powershell

  • Thread starter Thread starter Arbelac
  • Start date Start date
A

Arbelac

Guest
If a user is a member of the "apps users" and/or "apps test users" group, the Value column will display the relevant group information. if a user is not a member of any group, it will display NULL. how can I do this?

Code:
$cyberarkAccounts = Get-ADUser -identity users01 -Properties samaccountname,enabled,memberof

$cyberarkAccountTable = @{}

foreach ($account in $cyberarkAccounts) {

$cyberarkAccountTable[$account.samaccountname] = $account.MemberOf  | %{(Get-ADGroup $_).sAMAccountName} |  Where-Object { $_ -like 'apps Users*' -or $_ -like 'apps test Users*'  }

}

My output:

Code:
Name       Value
---        ----
Users01
Users02    apps users
Users03    apps users,apps test Users

My desired output:

Code:
Name       Value
---        ----
Users01     NULL
Users02    apps users
Users03    apps users,apps test Users
<p>If a user is a member of the "apps users" and/or "apps test users" group, the Value column will display the relevant group information. if a user is not a member of any group, it will display NULL. how can I do this?</p>
<pre><code>$cyberarkAccounts = Get-ADUser -identity users01 -Properties samaccountname,enabled,memberof

$cyberarkAccountTable = @{}

foreach ($account in $cyberarkAccounts) {

$cyberarkAccountTable[$account.samaccountname] = $account.MemberOf | %{(Get-ADGroup $_).sAMAccountName} | Where-Object { $_ -like 'apps Users*' -or $_ -like 'apps test Users*' }

}
</code></pre>
<p>My output:</p>
<pre><code>Name Value
--- ----
Users01
Users02 apps users
Users03 apps users,apps test Users
</code></pre>
<p>My desired output:</p>
<pre><code>Name Value
--- ----
Users01 NULL
Users02 apps users
Users03 apps users,apps test Users
</code></pre>
Continue reading...
 

Latest posts

Top