Get-ADUser cannot get data from my variable

Hi have a really strange problem using get-qaduser.

Here is the script that I am using:

$Source = "C:\Temp\Source.txt"
Connect-QADService -Service "ActiveRolesServer" -Proxy
ForEach ($UPN in GC $Source)
{
Get-QADUser -identity $UPN | Select-Object -Property UserPrincipalName,MobilePhone

This is the result I am getting:

When trying the query I get nothing in return.

When running $UPN alone I get the last name in my $Source variable, which is good.

When running the script replacing the $UPN by user@upn.com, all is good

But when running the query from the script the result is empty.

Any idea?

Also, when running it from another computer, the script is working like intended. 

Parents
  • Got it!!

    Like any problem of that kind, the problem was with a previous command. Someone changed the source file and the file was using "upn". I have to remove the double quote for each line.

    So when the script was reading the file it was trying to do: Get-QADUser -Identity "first.last@domain.com" and not Get-QADUser -Identity first.last@domain.com.

    I got an error message when I tried to make a Get-ADUser, the Get-QADUser was only returning nothing, no error at all.

    So I added those lines:

    $Source="C:\Temp\SourceFile.txt"
    (Get-Content $Source) | Foreach-Object {$_ -replace '"', ''}|Out-File $Source

    Then when trying the 

    $Source = "C:\Temp\Source.txt"
    Connect-QADService -Service "ActiveRolesServer" -Proxy
    ForEach ($UPN in GC $Source)
    {
    Get-QADUser -identity $UPN | Select-Object -Property UserPrincipalName,MobilePhone

    The query is working!

    Sorry for all the troubles!

    Mathieu

Reply
  • Got it!!

    Like any problem of that kind, the problem was with a previous command. Someone changed the source file and the file was using "upn". I have to remove the double quote for each line.

    So when the script was reading the file it was trying to do: Get-QADUser -Identity "first.last@domain.com" and not Get-QADUser -Identity first.last@domain.com.

    I got an error message when I tried to make a Get-ADUser, the Get-QADUser was only returning nothing, no error at all.

    So I added those lines:

    $Source="C:\Temp\SourceFile.txt"
    (Get-Content $Source) | Foreach-Object {$_ -replace '"', ''}|Out-File $Source

    Then when trying the 

    $Source = "C:\Temp\Source.txt"
    Connect-QADService -Service "ActiveRolesServer" -Proxy
    ForEach ($UPN in GC $Source)
    {
    Get-QADUser -identity $UPN | Select-Object -Property UserPrincipalName,MobilePhone

    The query is working!

    Sorry for all the troubles!

    Mathieu

Children
No Data