Compare two list and find names that are in list one and not list two using powershell

孤街浪徒 提交于 2019-12-03 08:49:42

I assume $FolderList and $AdUserName are arrays of strings? You don't really need Compare-Object to compare arrays. It's as simple as this:

$FolderList | ?{$AdUserName -notcontains $_}

 

Compare-Object is for comparing the specified properties of collections of objects with common properties. You could do this with Compare-Object if you really want, like this:

Compare-Object $FolderList $AdUserName | ?{$_.SideIndicator -eq '<='} | Select-Object -ExpandProperty InputObject

But as you can see, it's overkill for this task.

To output the result to another variable, simply assign it:

$AnotherVariable = $FolderList | ?{$AdUserName -notcontains $_}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!