Feeling Stupid

Home Forums Scripting PowerShell Feeling Stupid

Tagged: 

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    killerbee
    Participant
    #651665

    Trying to do a very simple task with powershell, but do not get it to work, and fail to see what is wrong. I got a simple CSV, which has only one header (emailaddress).
    Emailaddress
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    etc
    I am trying to get the aduser, as the UserPrincipalName in our environment is equal to the email address. No matter how it try the query, it always fails to retrieve any objects:
    Import-csv -Path C:\Temp\List.csv | Foreach-Object {Write-Host “$($_.EmailAddress)”; Get-AdUser -Filter {UserPrincipalName -eq “$_.EmailAddress”} -Server GlobalCataloge.Domain.prefix:3268}

    $inv = Import-csv -Path C:\Temp\list.csv
    foreach ($u in $inv) {Write-Host “$($U.EmailAddress)”; Get-aduser -Filter {UserPrincipalName -eq “$u.EmailAddress”} -Server Globalcataloge.domain.prefix:3268}

    $inv = Get-content C:\Temp\list.csv
    foreach ($u in $inv) {Write-Host “$($U.EmailAddress)”; Get-aduser -Filter {UserPrincipalName -eq “$u.EmailAddress”} -Server Globalcataloge.domain.prefix:3268}

    The write-host always displayes the correct value, however the query returns nothing, but when i run the command with the value, then the object is returned.

    Get-aduser -Filter {UserPrincipalName -eq “[email protected]”} -Server Globalcataloge.domain.prefix:3268

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.