Get-CsUser | Get-QADUser

by FloydTheDuck at 2013-05-01 14:27:22

I’m trying to get a group of users that have 2 qualifiers: 1) They don’t currently have Lync, and 2) They’re located at X office

I’ve used the following syntax respectively:
#Because any users with domain.com as their SIP are on Lync, I will find all users that do not have this (which means they don’t have Lync)
1) Get-CsUser | Where {$.SipAddress -notlike “*domain.com”} | Select-Object DisplayName, Enabled, SipAddress | Export-CSV C]
#Get the users that are in X office
2) Get-QADUser -SizeLimit 0 | Where {$
.Office -like “X*”} | Select-Object name, samaccountname, email, office, lastlogon | Export-CSV C]

Rather than having all users in X office (with both users who do and do not have Lync), and then another CSV with all non-Lync users (across all offices) I wanted to pipe the commands together.
What I tried:
Get-CsUser | Where {$.SipAddress -notlike “*domain.com”} | Where {$.Enabled -eq “True”} | Select-Object DisplayName | Get-QADUser| Select-Object Name,Office,Email

Error I received]Get-QADUser : The input object cannot be bound to any parameters for the command either because the command does not take pipeline
input or the input and its properties do not match any of the parameters that take pipeline input.
At line:1 char:120
+ … DisplayName | Get-QADUser| Select-Object Name,Office,Email


Is there anyway to pipe these commands together? Or am I going about this completely the wrong way?

I’ve also tried exporting command 1 to a csv, then importing into command 2, as well as setting $NonLyncUsers = 1st command and then using that in command 2… no luck with those either (similar errors).

Thanks!
by Nobody at 2013-05-01 15:16:19
What about something like this


$users = Get-CsUser | Where-object {($.SipAddress -notlike “*domain.com”) -and ($.Enabled -eq “True”)}|
select-object displayname
$result = @()
foreach ($user in $users){
$result += @(Get-QADUser “$($user.displayname)”| Select-Object Name,Office,Email)
}

$result
by poshoholic at 2013-05-02 06:04:46
Also, instead of using Where-Object to filter on enabled users (which is being done incorrectly right now – never compare a boolean to a string), and instead of filtering on SipAddress in Where-Object, both of which are client-side filtering mechanisms, you should filter on the server instead, like this:
Get-CsUser -Filter {Enabled –eq $true -and SipAddress -like ‘*domain.com’}
Note that I don’t have these cmdlets to test on my system, so this may have a typo or small syntax error. The points are the same regardless: you should use server-side filtering, and you should compare boolean values to boolean $true or $false instead of strings. For that last point, if you’re wondering why, consider the results of this:
$true -eq 'False’
That will always return true, regardless of what string you put on the right-hand side. Any non-empty string converts implicitly into boolean true and any empty string converts implicitly into boolean false.
by FloydTheDuck at 2013-05-02 13:37:25
Thanks all! The hash table is what I needed :slight_smile: