Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Filter out unwanted item in a list of variables

$
0
0

I have this snippet of code that I need help filtering the output

 

get-ADPermission-Identity'CN=TdF.york@york.gov.uk,OU=SharedMailboxes,OU=Users,OU=CYC,DC=york,DC=gov,DC=uk'  |Where-Object {($_.Deny -like"False") -and ($_.User -like"cyc\*")-and ($_.AccessRights -Like"ExtendedRight")} |ForEach-Object {

 Write-Host$_.User,$_.Deny,$_.AccessRights 

 $Sam=Split-Path$_.User -Leaf

 Get-ADUser$Sam}

 

 

The Get-ADuser returns some objects I don’t want listed like these

DistinguishedName : CN=SERVICE_FSUSER,OU=SystemAccounts,OU=Users,OU=CYC,DC=york,DC=gov,DC=uk

 

DistinguishedName : CN=MRE{16BFD22C-B63C-484F-B835-7F3BB9C303C3},CN=Users,DC=york,DC=gov,DC=uk

 

I want something like

Get-aduser $Sam | Where-Objectdoes not contain this {($_.distinguishedName -like"CN=MRE*") -and ($_.$_.distinguishedName -like"*OU=SystemAccounts,OU=Users,OU=CYC,DC=york,DC=gov,DC=uk")} | Write-Host $_.Name


Viewing all articles
Browse latest Browse all 6937

Trending Articles