none
Need help with Powershell query RRS feed

  • Question

  • Hello,

    I am trying to run a command to find all machines in an OU with "dallas" in the description string. My command is as follows:

    Get-ADcomputer -filter 'description -like "*dallas*"' -SearchBase "OU=Inactive-Workstations,OU=Workstations,DC=enterprisenet,DC=org" |
     Select-Object Name, Description |
     Export-Csv C:\SW_Share\Scripts\Script_Output\inactive.csv -NoType

    The problem I am having is that the file that is outputted has the correct machine names but the description is blank.

    Example:

    Name Description
    USLCNU1360JP9
    UST003730152853

    USDHL4PDX1

    I need both...

    any help would be appreciated as I am not the best powershell scripter.

    Sunday, January 10, 2016 11:26 PM

Answers

  • Try:

    Get-ADcomputer -filter 'description -like "*dallas*"' -SearchBase "OU=Inactive-Workstations,OU=Workstations,DC=enterprisenet,DC=org" -Properties description

    followed by the pipe and the rest of your statement.

    Richard Mueller - MVP Enterprise Mobility (Directory Services)

    • Marked as answer by Shane199098 Monday, January 11, 2016 1:36 AM
    Monday, January 11, 2016 1:23 AM
    Moderator

All replies

  • Help Get-AdComputer -Full

    You must learn to lok up these things.  It is the only way to learn PowerSHell CmdLets.

    You keep forgetting that you have to ask for the properties that are not the basic few returned.

    Ask yourself,  "Self, how do I know what properties are returned?"

    Answer: "CmdLet help is designed t help answer that question".

    You can also use Get-Member.

    All of this is chapter 1 of PowerShell 101.  Take the time to learn it.  It will save you hundreds of hours of confusion.


    \_(ツ)_/

    Sunday, January 10, 2016 11:47 PM
  • The first thing we always do is to review the parameters and usage then we look carefully at the examples.

    https://technet.microsoft.com/en-us/library/ee617192.aspx?f=255&MSPPError=-2147217396

    We can learn a new PowerShell CmdLet in a few minutes of reading the help.  90% of all bad advice in forums is because the adviser has never read the help.


    \_(ツ)_/

    Sunday, January 10, 2016 11:50 PM
  • Description is not a default property of Get-ADComputer, like Name. You must specify it with the -Properties parameter of Get-ADComputer.

    Edit: Documentation of default and extended properties exposed by Get-ADComputer:

    http://social.technet.microsoft.com/wiki/contents/articles/12056.active-directory-get-adcomputer-default-and-extended-properties.aspx

    Definition (mine) of default and extended properties, and use of -Properties parameter:

    http://social.technet.microsoft.com/wiki/contents/articles/12031.active-directory-powershell-ad-module-properties.aspx


    Richard Mueller - MVP Enterprise Mobility (Directory Services)


    Sunday, January 10, 2016 11:50 PM
    Moderator
  • Just a bit of clarification.  THe question is "need help in ....".  To ask a question like that without checking help seems a bit naïve and foolish.

    I think we all need to point new computer users towards doing basic research starting with the builtin help.  It is the most valuable lesson a novice can learn. 

    In most of my early jobs as a tech and programmer I would have been fired for asking questions that were answered in the documentation. 


    \_(ツ)_/

    Sunday, January 10, 2016 11:56 PM
  • Help Get-AdComputer -Full

    You must learn to lok up these things.  It is the only way to learn PowerSHell CmdLets.

    You keep forgetting that you have to ask for the properties that are not the basic few returned.

    Ask yourself,  "Self, how do I know what properties are returned?"

    Answer: "CmdLet help is designed t help answer that question".

    You can also use Get-Member.

    All of this is chapter 1 of PowerShell 101.  Take the time to learn it.  It will save you hundreds of hours of confusion.


    \_(ツ)_/


    ok not the help I was expecting... Look I have tried to read the help but it just doesn't make since to me its just faster to ask for help. I could spend hours reading and reading and not get anything accomplished. I love scripting but powershell is hard to me.
    Monday, January 11, 2016 12:01 AM

  • ok not the help I was expecting... Look I have tried to read the help but it just doesn't make since to me its just faster to ask for help. I could spend hours reading and reading and not get anything accomplished. I love scripting but powershell is hard to me.

    If you are going to be a technician you have to learn to read the help. It is so simple that once yu see how to use it you will constantly go to it as a primary source.

    Start by typing "help help" and read how to use help.


    \_(ツ)_/

    Monday, January 11, 2016 12:15 AM
  • Get-ADcomputer -Properties 'description -like "*dallas*"' -SearchBase "OU=Inactive-Workstations,OU=Workstations,DC=enterprisenet,DC=org" |
     Select-Object Name, Description |
     Export-Csv C:\SW_Share\Scripts\Script_Output\inactive.csv -NoType


    PS C:\WINDOWS\system32> C:\SW_Share\Scripts\Get Inactive Workstations.ps1
    cmdlet Get-ADComputer at command pipeline position 1
    Supply values for the following parameters:
    (Type !? for Help.)
    Filter: CN, Description
    Get-ADcomputer : Error parsing query: 'CN, Description' Error Message: 'Operator Not
    supported: ' at position: '3'.
    At C:\SW_Share\Scripts\Get Inactive Workstations.ps1:1 char:1
    + Get-ADcomputer -Properties 'description -like "*dallas*"' -SearchBase "OU=Inacti ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ParserError: (:) [Get-ADComputer], ADFilterParsingException
        + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.A
       DFilterParsingException,Microsoft.ActiveDirectory.Management.Commands.GetADComputer

    Monday, January 11, 2016 12:26 AM
  • Get-ADcomputer -Filter * -Properties 'description -like "*dallas*"' -SearchBase "OU=Inactive-Workstations,OU=Workstations,DC=enterprisenet,DC=org" |
     Select-Object Name, Description |
     Export-Csv C:\SW_Share\Scripts\Script_Output\inactive.csv -NoType

    PS C:\WINDOWS\system32> C:\SW_Share\Scripts\Get Inactive Workstations.ps1
    Get-ADcomputer : One or more properties are invalid.
    Parameter name: description -like "*dallas*"
    At C:\SW_Share\Scripts\Get Inactive Workstations.ps1:1 char:1
    + Get-ADcomputer -Filter * -Properties 'description -like "*dallas*"' -SearchBase  ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-ADComputer], ArgumentException
        + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.Act
       iveDirectory.Management.Commands.GetADComputer

    Monday, January 11, 2016 12:48 AM
  • as an admin elevated

    update-help -force


    \_(ツ)_/

    Monday, January 11, 2016 12:53 AM
  • as an admin elevated

    update-help -force


    \_(ツ)_/

    That does nothing but update help man. I see this site is a DEAD END. Your lucky you don't get graded on your customer service here because if you did you would be Fired you have been nothing but RUDE to me. All you do is throw help sites at me instead of actually helping me. I thought that's what this forum was for to get assistance with scripting. Thanks for nothing.

    I'll be sure to fill out the survey and let them know how rude YOU have been.

    Monday, January 11, 2016 1:04 AM
  • Try:

    Get-ADcomputer -filter 'description -like "*dallas*"' -SearchBase "OU=Inactive-Workstations,OU=Workstations,DC=enterprisenet,DC=org" -Properties description

    followed by the pipe and the rest of your statement.

    Richard Mueller - MVP Enterprise Mobility (Directory Services)

    • Marked as answer by Shane199098 Monday, January 11, 2016 1:36 AM
    Monday, January 11, 2016 1:23 AM
    Moderator
  • Try:

    Get-ADcomputer -filter 'description -like "*dallas*"' -SearchBase "OU=Inactive-Workstations,OU=Workstations,DC=enterprisenet,DC=org" -Properties description

    followed by the pipe and the rest of your statement.

    Richard Mueller - MVP Enterprise Mobility (Directory Services)


    Finally some help! Thank you that was exactly what I was trying to get.
    Monday, January 11, 2016 1:37 AM
  • jrv, please refrain from namecalling; thanks.

    -- Bill Stewart [Bill_Stewart]

    Monday, January 11, 2016 3:28 PM
    Moderator
  • jrv, please refrain from namecalling; thanks.

    -- Bill Stewart [Bill_Stewart]

    I apologize.  Sometimes rude and annoying people get to me.  I will be more careful.


    \_(ツ)_/

    Monday, January 11, 2016 3:38 PM