locked
PowerShell Piping: What am I missing RRS feed

  • Question

  • I have several users that have incorrect/unauthorized information added to their Active Directory accounts.  What I am trying to do, is to use PS to pull all of the users from a specific OU, with a Specific job title (Advisors), and pipe the search into a set-aduser commands that is designed to clear all of the physical address and telephone numbers.  I've tried running the command below, but it tells me that I have an EmptyPipeElement error.

    Get-ADUser -SearchBase “OU=Advisors,OU=Users,OU=Test_OU,OU=Production,DC=osxmx,DC=com” -Filter  -LDAPFilter "(department=$Advisors)" | set-aduser -City “ “ -Country “ “ -HomePhone “ “ -MobilePhone “ “ -Office “ “ -OfficePhone “ “ -PostalCode “ “ -State “ “ -POBox “ “ -StreetAddress “ “ -Fax “ “  -Clear pager,ipphone

    I will admit, I am rusty with my Active Directory for Windows PowerShell skills, especially since I moved to supporting a Unix environment.

    Tuesday, October 3, 2017 4:29 PM

All replies

  • Try TechNet script page(s)

    https://technet.microsoft.com/en-us/scriptcenter

    From the above link,PowerShell & Scripts are at youre availability..

    Tuesday, October 3, 2017 4:33 PM
  • You cannot specify both "Filter" and "LDAPFilter"

    \_(ツ)_/

    Tuesday, October 3, 2017 4:42 PM
  • This would be how to format and layout code that is readable and easier to debug.

    $propToClear = @(
    	'City', 'Country', 'HomePhone',
    	'MobilePhone', 'Office', 'OfficePhone',
    	'PostalCode', 'State', 'POBox',
    	'StreetAddress', 'Fax', 'pager', 'ipphone'
    )
    $searchBase = 'OU=Advisors,OU=Users,OU=Test_OU,OU=Production,DC=osxmx,DC=com'
    Get-AdUser -LDAPFilter "(department=$Advisors)" -SearchBase $searchBase| 
    	Set-AdUser -Clear $propToClear
    This is even how to design code on Unix.


    \_(ツ)_/


    • Edited by jrv Tuesday, October 3, 2017 4:49 PM
    Tuesday, October 3, 2017 4:49 PM
  • This the error I get when running the newly provided format:

    Get-ADUser : Directory object not found

    At line:8 char:11

    + Get-AdUser <<<<  -LDAPFilter "{department=Advisors}" -SearchBase $searchBase|

        + CategoryInfo          : ObjectNotFound: (:) [Get-ADUser], ADIdentityNotF

       oundException

        + FullyQualifiedErrorId : Directory object not found,Microsoft.ActiveDirec

       tory.Management.Commands.GetADUser

    Tuesday, October 3, 2017 6:07 PM
  • is $searchBase correct for your environment?

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Tuesday, October 3, 2017 6:30 PM
  • You keep changing the code without understanding what you are doing.  Please take the time to learn PowerShell and the AD CmdLets.  What you are running is NOT what I posted.  You edited it badly for som unknown reason.

    You cannot exchange () for {}.  It almost never works.  Learn what these things mean in there various usages.


    \_(ツ)_/

    Tuesday, October 3, 2017 9:57 PM
  • The commands you had posted returned a double chevron every time I ran it.  I attempted to change the parameters a little bit to see if that would complete the command.  As I do not use PowerShell on a consistent enough basis and my long term path has no realistic use for an extensive knowledge in PowerShell; I was hoping for some quick assistance from fellow IT colleagues as opposed to sitting down to study while juggling my various tasks.

    Clearly I chose wrong.  

    Thank you for your time and assistance, and my apologies for the inconvenience.

    Wednesday, October 4, 2017 12:56 AM
  • The commands I posted work for me.

    Run this:

    $searchBase = 'OU=Advisors,OU=Users,OU=Test_OU,OU=Production,DC=osxmx,DC=com'
    $advisors='????'
    Get-AdUser -LDAPFilter "(department=$Advisors)" -SearchBase $searchBase

    Don't forget to assign the variables first.

    Your searchbase looks pretty bad. Be sure it is correct.


    \_(ツ)_/

    Wednesday, October 4, 2017 1:11 AM
  • .. or
    department=$Advisors  seemy kinda weird to me 

    Wednesday, October 4, 2017 6:52 AM
  • .. or
    department=$Advisors  seemy kinda weird to me 

    It filters on the department attribute of a group account.  Why is that odd?  Of course if the schema has not been extended then it may de that he means "Description".  The assumption is that the command returns groups but just not enough groups.  If that was a bad filter then the there would never be a result.

    My last post would resolve this if the OP runs it.


    \_(ツ)_/

    Wednesday, October 4, 2017 9:26 AM
  • Minor corrections. Please find the working command below.

    Get-ADUser -SearchBase  “OU=Advisors,OU=Users,OU=Test_OU,OU=Production,DC=osxmx,DC=com” -Filter {department -like "advisors"} | set-aduser -City “ “ -Country “ “ -HomePhone “ “ -MobilePhone “ “ -Office “ “ -OfficePhone “ “ -PostalCode “ “ -State “ “ -POBox “ “ -StreetAddress “ “ -Fax “ “  -Clear pager,ipphone

    Wednesday, October 4, 2017 12:58 PM
  • Minor corrections. Please find the working command below.

    Get-ADUser -SearchBase  “OU=Advisors,OU=Users,OU=Test_OU,OU=Production,DC=osxmx,DC=com” -Filter {department -like "advisors"} | set-aduser -City “ “ -Country “ “ -HomePhone “ “ -MobilePhone “ “ -Office “ “ -OfficePhone “ “ -PostalCode “ “ -State “ “ -POBox “ “ -StreetAddress “ “ -Fax “ “  -Clear pager,ipphone

    "Like" should be "-eq".  "-like" requires a wildcard.  You can clear all filed with -Clear <field list>.  See the documentation.

    From my earlier post:

    $propToClear = @(
    	'City', 'Country', 'HomePhone',
    	'MobilePhone', 'Office', 'OfficePhone',
    	'PostalCode', 'State', 'POBox',
    	'StreetAddress', 'Fax', 'pager', 'ipphone'
    )
    $searchBase = 'OU=Advisors,OU=Users,OU=Test_OU,OU=Production,DC=osxmx,DC=com'
    Get-AdUser -LDAPFilter "(department=$Advisors)" -SearchBase $searchBase| 
    	Set-AdUser -Clear $propToClear
    Learn PowerShell: https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276


    \_(ツ)_/

    • Proposed as answer by I.T Delinquent Wednesday, October 4, 2017 1:11 PM
    Wednesday, October 4, 2017 1:07 PM