none
SCCM Device Collection Members TO AD Security Group - Error Cannot find an object with identity: '$' RRS feed

  • שאלה

  • Anyone have any idea why I would get this error? This One liner Command Script, works perfectly inside the SCCM Powershell Admin Console. However when i connect in by New-PSDrive i get the error below? 

    Even if i add the identity along with Distinguished name or SID, I still get the error. 

    Any ideas?

    (Get-CMDevice -CollectionName "SCCMDeviceCollectionNameHere").name |ForEach-Object{Add-ADGroupMember "ADDGROUPNAMEHERE" -Members $_$ }

    Add-ADGroupMember : Cannot find an object with identity: '$' under: 'DC=sub,DC=domain,DC=com'.
    At C:\ADD-ADGroupMember2.ps1:11 char:83
    + ... Each-Object{Add-ADGroupMember "ADGROUPNameHere ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: ($:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     

    שבת 20 אפריל 2019 01:06

תשובות

  • That's good!

    Now try this:

    Get-CMDevice -CollectionName "Intl Home Worker PCI Subnet" | 
        Select -ExpandProperty Name | 
            ForEach-Object{ Add-ADGroupMember "ADDGROUPNAMEHERE" -Members $_ }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Rich... I think you might have solved it. I just added an extra " $ " 

    Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE" | 
        Select -ExpandProperty Name | 
            ForEach-Object{ Add-ADGroupMember -Identity "SCCM_Intl_Home_Worker_PCI_Subnet" -Members $_$ }

    It works!!!! No more error. That one little Select piece with Expand property did it! Now I will Automate it by Schedule to know for sure it works. Thanks for helping figure this out!


    • סומן כתשובה על-ידי Chris480602 יום רביעי 24 אפריל 2019 17:17
    • נערך על-ידי Chris480602 יום רביעי 24 אפריל 2019 17:42
    יום רביעי 24 אפריל 2019 16:43

כל התגובות

  • Looks like you've got an additional "$" in the "-Members" parameter value. It should be "$_", not "$_$"

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    שבת 20 אפריל 2019 01:29
  • Okay, I tried that before. I will give that another shot and see if it works. What I am doing here is the Device Collection has a list of Computer names in it. I am taking that and sending it to the Security Group. The idea is to automatically update the Security Group without any user interaction. So the names from “ CollectionName “ must be passed to Security Group. Works fine from SCCM powershell but it fails in regular power shell. SCCM is likely passing the parameter because it’s embedded into the Module.
    שבת 20 אפריל 2019 01:53
  • If you're unsure what's being sent through the pipeline, try running this and see what's there:

    (Get-CMDevice -CollectionName "SCCMDeviceCollectionNameHere").name | ForEach-Object{ $_ }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    שבת 20 אפריל 2019 02:33
  • When i run that leaving inside the ForEach clause with $_ , there is no output. The problem happens only when it's passed to the AD Security group to add the members in: 

    Add-ADGroupMember "ADDADGROUPNAMEHERE" -Members $_



    • נערך על-ידי Chris480602 יום שני 22 אפריל 2019 15:36
    יום שני 22 אפריל 2019 15:32
  • You said this works with SCCM PowerShell?  So if you open the SCCM console, go to the top left, click the little drop down arrow and select Connect via Windows PowerShell ISE, this will output all of the code that you need to import the SCCM module upon running the script.  Just add your bit of code in the appropriate section.

    To install the SCCM PowerShell modules you can simple install the SCCM console, and then run the script from that machine.

    In the end, the only differene between using SCCM PowerShell vs your own is that you have to write the import-module seciton.

    יום שני 22 אפריל 2019 16:27
  • Could this be your problem?

    https://www.reddit.com/r/SCCM/comments/5oxp94/getcmdevice_returns_nothing_why/


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    יום שני 22 אפריל 2019 18:10
  • Tried it. Get the Same Error. For whatever reason, When i Click " Connect via Powershell " inside of SCCM I do not get the error. 
    יום שני 22 אפריל 2019 21:56
  • The resource ID wouldnt be the fix here because that is only associated with SCCM not Active Directory. 

    Also the Site Code is not the issue because i am able to connect to the PS-Drive Okay. 

    This strictly relates to passing a parameter to the argument from device collection to AD argument. Active Directory wants to accept it but when it's not launched from SCCM Console Powershell Connect it will not fill the Security Group with the Collection Members. 

    Still havent figured out what's causing this issue or how to fix it. 


    • נערך על-ידי Chris480602 יום שני 22 אפריל 2019 23:19
    יום שני 22 אפריל 2019 22:11
  • Can you get the SCCM collection members without using the SCCM console connect to PowerShell?  Sounds like the answer is yes. 

    Try this

    $devices = Get-CMDevice -CollectionName "xxx"
    
    foreach($device in $devices)
    {
    	Add-ADGroupMember -Identity "SomeName" -Members $device.Name	
    }

    יום שלישי 23 אפריל 2019 13:54
  • Here is what i get below. Unexpected token. This appears in the SCCM connect powershell window. When i run it in Powershell ISE it doesnt show an error at all, however it doesnt add any computers to the security group. 

    PS BW1:\> $devices = Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE" foreach ($device in
    $devices) { Add-ADGroupMember -Identity "ADGROUPNAMEHERE" -Members $device.Name }
    At line:1 char:88
    + ... lectionName "DEVICECOLLECTIONNAMEHERE" foreach ($device in $device ...
    +                                                                ~~
    Unexpected token 'in' in expression or statement.
    At line:1 char:87
    + ... CollectionName "DEVICECOLLECTIONNAMEHERE" foreach ($device in $dev ...
    +                                                                  ~
    Missing closing ')' in expression.
    At line:1 char:99
    + ... e "DEVICECOLLECTIONNAMEHERE" foreach ($device in $devices) { Add-A ...
    +                                                                 ~
    Unexpected token ')' in expression or statement.
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : UnexpectedToken



    • נערך על-ידי Chris480602 יום שלישי 23 אפריל 2019 17:32
    יום שלישי 23 אפריל 2019 15:15
  • Shouldn't foreach be on a new line?
    יום שלישי 23 אפריל 2019 17:42
  • I thought It can be used as a statement, loop or a condition. 

    Ive seen it used multiple ways. I can change it. I just want to get this working so the Device Collection will automatically update the Security Group by command. 

    Ive seen some people struggle with this in Active Directory. Not sure what the cause is of this. 


    • נערך על-ידי Chris480602 יום שלישי 23 אפריל 2019 17:47
    יום שלישי 23 אפריל 2019 17:46
  • did you run the code I posted?  The blob you posted isn't correct

    יום שלישי 23 אפריל 2019 17:54
  • @mrasmussen

    Yes. I actually did use your code for that error above. What do i have wrong? 

    Your code doesnt throw in error in Powershell ISE but it does not add devices to the Security Group. In SCCM Powershell Window, it gives me an unexpected token error. 


    • נערך על-ידי Chris480602 יום שלישי 23 אפריל 2019 18:05
    יום שלישי 23 אפריל 2019 18:04
  • does this work

    $devices = Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE" 
    foreach ($device in $devices) 
    { 
    $device.Name 
    }

    יום שלישי 23 אפריל 2019 18:08
  • @mrasmussen

    Where does the ADD-ADGroupmember need to go, in order to add to the security group? 

    יום שלישי 23 אפריל 2019 18:10
  • Move the "foreach" to a new line.

    $devices = Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE"
    foreach ($device in $devices) { 
        Add-ADGroupMember -Identity "ADGROUPNAMEHERE" -Members $device.Name 
    }
    


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    יום שלישי 23 אפריל 2019 18:12
  • @Rich Matheisen [Ex-MVP (retired)]

    Just tried it. Runs without error, but doesnt add anything to the security group. 

    • נערך על-ידי Chris480602 יום שלישי 23 אפריל 2019 18:14
    יום שלישי 23 אפריל 2019 18:14
  • I was just verifying that the Get-CMDevice cmdlet was working properly, you should see a list of names ($device.Name)
    יום שלישי 23 אפריל 2019 19:10
  • @Rich Matheisen [Ex-MVP (retired)]

    Actually I do not see a list of names. With your code below: 

    $devices = Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE" 
    foreach ($device in $devices) 
    { 
    $device.Name 
    }

    There is no output with that above code inside Powershell ISE with Connection Script. 


    • נערך על-ידי Chris480602 יום שלישי 23 אפריל 2019 19:14
    יום שלישי 23 אפריל 2019 19:13
  • That means that your Get-CMDevice isn't returning any devices.  check that your CollectionName is correct.
    יום שלישי 23 אפריל 2019 19:18
  • @mrasmussen

    I just tested my original code and it is fine with exception of it not working in Powershell ISE. The Name still exists. I even tried your code with the Collection ID and it still didnt return any names.

    (Get-CMDevice -CollectionName "SCCMDeviceCollectionNameHere").name |ForEach-Object{Add-ADGroupMember "ADDGROUPNAMEHERE" -Members $_$ }


    In the VERBOSE output (of your code) I do see that it does show when i select the names from that collection name in the database.


    • נערך על-ידי Chris480602 יום שלישי 23 אפריל 2019 19:52
    יום שלישי 23 אפריל 2019 19:32
  • I didn't expect that it would. That change only fixes your coding problem.

    I think you've already established that the Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE" doesn't return anything.

    Try adding "-Verbose" to that cmdlet's parameters and see if the output from that sheds any light on your situation.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    יום שלישי 23 אפריל 2019 21:14
  • I didn't expect that it would. That change only fixes your coding problem.

    I think you've already established that the Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE" doesn't return anything.

    Try adding "-Verbose" to that cmdlet's parameters and see if the output from that sheds any light on your situation.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    That does display all of the members in my collection and it shows the WQL query. below:

    VERBOSE: Finish: Execution of WQL query: SELECT * FROM SMS_CM_RES_COLL_BW1001FD. Processed 11 results in
    00:00:01.7870961.
    VERBOSE: Finish: Execution of WQL query: SELECT * FROM SMS_Collection WHERE Name = 'Intl Home Worker PCI Subnet'.
    Processed 1 results in 00:00:01.9081675.

    יום שלישי 23 אפריל 2019 21:19
  • So, is it possible that the objects simply have no member called "name"?

    What's the class of an item returned from the query? What are the property names in an item?

    This should get you the data needed to answer those two questions.

    $devices = Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE"
    $devices[0].GetType()
    $devices[0]|gm
    Maybe "name" should be "MS-SMS-MP-Name"? That's just a wild guess based on the schema exensions from config manager.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    יום שלישי 23 אפריל 2019 23:48
  • So, is it possible that the objects simply have no member called "name"?

    What's the class of an item returned from the query? What are the property names in an item?

    This should get you the data needed to answer those two questions.

    $devices = Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE"
    $devices[0].GetType()
    $devices[0]|gm
    Maybe "name" should be "MS-SMS-MP-Name"? That's just a wild guess based on the schema exensions from config manager.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    I copied just the " Name " Property under gm, else i can copy all of the output. 

    GetType

    -----------------------------------------

    TypeName   : IResultObject#SMS_CM_RES_COLL_BW1001FD
    Name       : Name
    MemberType : Property
    Definition : Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlResultObject Name {get;set;}

    GM 

    -------------------------------------------------------------------

    Module                     : AdminUI.WqlQueryEngine.dll
    Assembly                   : AdminUI.WqlQueryEngine, Version=5.0.0.0, Culture=neutral,
                                 PublicKeyToken=31bf3856ad364e35
    TypeHandle                 : System.RuntimeTypeHandle
    DeclaringMethod            :
    BaseType                   : Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlResultObjectBa
                                 se
    UnderlyingSystemType       : Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlResultObject
    FullName                   : Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlResultObject
    AssemblyQualifiedName      : Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlResultObject,
                                 AdminUI.WqlQueryEngine, Version=5.0.0.0, Culture=neutral,
                                 PublicKeyToken=31bf3856ad364e35
    Namespace                  : Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
    GUID                       : 07057d47-4533-38c5-9f32-f3b4b119f429
    IsEnum                     : False
    GenericParameterAttributes :
    IsSecurityCritical         : True
    IsSecuritySafeCritical     : False
    IsSecurityTransparent      : False
    IsGenericTypeDefinition    : False
    IsGenericParameter         : False
    GenericParameterPosition   :
    IsGenericType              : False
    IsConstructedGenericType   : False
    ContainsGenericParameters  : False
    StructLayoutAttribute      : System.Runtime.InteropServices.StructLayoutAttribute
    Name                       : WqlResultObject
    MemberType                 : TypeInfo
    DeclaringType              :
    ReflectedType              :
    MetadataToken              : 33554443
    GenericTypeParameters      : {}
    DeclaredConstructors       : {Void
                                 .ctor(Microsoft.ConfigurationManagement.ManagementProvider.ConnectionManagerBase,
                                 Microsoft.ConfigurationManagement.ManagementProvider.SmsNamedValuesDictionary,
                                 System.Management.ManagementObject), Void
                                 .ctor(Microsoft.ConfigurationManagement.ManagementProvider.ConnectionManagerBase,
                                 Microsoft.ConfigurationManagement.ManagementProvider.SmsNamedValuesDictionary,
                                 System.Management.ManagementBaseObject,
                                 Microsoft.ConfigurationManagement.ManagementProvider.AsyncOperationDatabase)}
    DeclaredEvents             : {}
    DeclaredFields             : {}
    DeclaredMembers            : {System.Management.ManagementObject get_ManagedObject(), Void Dispose(Boolean), Void
                                 Delete(), Void
                                 Delete(Microsoft.ConfigurationManagement.ManagementProvider.ReportProgress)...}
    DeclaredMethods            : {System.Management.ManagementObject get_ManagedObject(), Void Dispose(Boolean), Void
                                 Delete(), Void
                                 Delete(Microsoft.ConfigurationManagement.ManagementProvider.ReportProgress)...}
    DeclaredNestedTypes        : {Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlResultObject+
                                 <GetEnumerator>d__30}
    DeclaredProperties         : {System.Management.ManagementObject ManagedObject, System.Collections.Generic.Diction
                                 ary`2[System.String,Microsoft.ConfigurationManagement.ManagementProvider.IResultObjec
                                 t] EmbeddedProperties, System.Collections.Generic.Dictionary`2[System.String,Microsof
                                 t.ConfigurationManagement.ManagementProvider.IResultObject] EmbeddedPropertyLists,
                                 System.String OverridingObjectClass...}
    ImplementedInterfaces      : {System.IDisposable, System.ICloneable,
                                 Microsoft.ConfigurationManagement.ManagementProvider.IResultObject2,
                                 Microsoft.ConfigurationManagement.ManagementProvider.IResultObject...}
    TypeInitializer            :
    IsNested                   : False
    Attributes                 : AutoLayout, AnsiClass, Class, Public, BeforeFieldInit
    IsVisible                  : True
    IsNotPublic                : False
    IsPublic                   : True
    IsNestedPublic             : False
    IsNestedPrivate            : False
    IsNestedFamily             : False
    IsNestedAssembly           : False
    IsNestedFamANDAssem        : False
    IsNestedFamORAssem         : False
    IsAutoLayout               : True
    IsLayoutSequential         : False
    IsExplicitLayout           : False
    IsClass                    : True
    IsInterface                : False
    IsValueType                : False
    IsAbstract                 : False
    IsSealed                   : False
    IsSpecialName              : False
    IsImport                   : False
    IsSerializable             : False
    IsAnsiClass                : True
    IsUnicodeClass             : False
    IsAutoClass                : False
    IsArray                    : False
    IsByRef                    : False
    IsPointer                  : False
    IsPrimitive                : False
    IsCOMObject                : False
    HasElementType             : False
    IsContextful               : False
    IsMarshalByRef             : False
    GenericTypeArguments       : {}
    CustomAttributes           : {}

    יום שלישי 23 אפריל 2019 23:57
  •  @Rich Matheisen [Ex-MVP (retired)]

    Also here are all properties

    PS BW1:\> $devices[0]|gm


       TypeName: IResultObject#SMS_CM_RES_COLL_BW1001FD

    Name                                     MemberType            Definition
    ----                                     ----------            ----------
    Clone                                    Method                System.Object Clone(), System.Object ICloneable....
    CompareTo                                Method                int CompareTo(System.Object obj), int IComparabl...
    ContainsObjectClass                      Method                bool ContainsObjectClass(string type), bool IRes...
    Delete                                   Method                void Delete(), void Delete(Microsoft.Configurati...
    Dispose                                  Method                void Dispose(), void IDisposable.Dispose()
    Equals                                   Method                bool Equals(System.Object obj)
    ExecuteMethod                            Method                Microsoft.ConfigurationManagement.ManagementProv...
    FormatDisplayString                      Method                string FormatDisplayString(string value), string...
    FormatQuery                              Method                string FormatQuery(string baseQuery, bool escape...
    Get                                      Method                void Get(), void Get(Microsoft.ConfigurationMana...
    GetArrayItems                            Method                System.Collections.Generic.List[Microsoft.Config...
    GetEnumerator                            Method                System.Collections.IEnumerator GetEnumerator(), ...
    GetHashCode                              Method                int GetHashCode()
    GetQualifierValue                        Method                System.Object GetQualifierValue(string qualifier...
    GetSingleItem                            Method                Microsoft.ConfigurationManagement.ManagementProv...
    GetType                                  Method                type GetType()
    Put                                      Method                void Put(), void Put(Microsoft.ConfigurationMana...
    SetArrayItems                            Method                void SetArrayItems(string propertyName, System.C...
    SetQualifierValue                        Method                void SetQualifierValue(string qualifierName, Sys...
    SetSingleItem                            Method                void SetSingleItem(string propertyName, Microsof...
    ToString                                 Method                string ToString()
    Item                                     ParameterizedProperty Microsoft.ConfigurationManagement.ManagementProv...
    AADDeviceID                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    AADTenantID                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    ActivationLockBypassState                Property              Microsoft.ConfigurationManagement.ManagementProv...
    ActivationLockBypassStateTimeStamp       Property              Microsoft.ConfigurationManagement.ManagementProv...
    ActivationLockState                      Property              Microsoft.ConfigurationManagement.ManagementProv...
    ADLastLogonTime                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    ADSiteName                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    AMTFullVersion                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    AMTStatus                                Property              Microsoft.ConfigurationManagement.ManagementProv...
    ATPLastConnected                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    ATPOnboardingState                       Property              Microsoft.ConfigurationManagement.ManagementProv...
    ATPOrgId                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    ATPSenseIsRunning                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    CAComplianceEvalTime                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    CAComplianceSetTime                      Property              Microsoft.ConfigurationManagement.ManagementProv...
    CAErrorDetails                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    CAErrorLocation                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    CAIsCompliant                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientActiveStatus                       Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientCertType                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientCheckPass                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientEdition                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientRemediationSuccess                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientState                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientType                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientVersion                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    CNAccessMP                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    CNIsOnInternet                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    CNIsOnline                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    CNLastOfflineTime                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    CNLastOnlineTime                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    CoManaged                                Property              Microsoft.ConfigurationManagement.ManagementProv...
    CurrentLogonUser                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceAccessState                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceCategory                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceOS                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceOSBuild                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceOwner                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceThreatLevel                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceType                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    Domain                                   Property              Microsoft.ConfigurationManagement.ManagementProv...
    EASDeviceID                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntispywareEnabled                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntispywareSignatureLastUpdateDateTime Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntispywareSignatureLastVersion        Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntivirusEnabled                       Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntivirusSignatureLastUpdateDateTime   Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntivirusSignatureLastVersion          Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPClientVersion                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPDeploymentDescription                  Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPDeploymentErrorCode                    Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPDeploymentState                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPEnabled                                Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPEngineVersion                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPInfectionStatus                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastFullScanDateTimeEnd                Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastFullScanDateTimeStart              Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastInfectionTime                      Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastQuickScanDateTimeEnd               Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastQuickScanDateTimeStart             Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastThreatName                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPendingFullScan                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPendingManualSteps                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPendingOfflineScan                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPendingReboot                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPolicyApplicationDescription           Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPolicyApplicationErrorCode             Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPolicyApplicationState                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPProductStatus                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    ExchangeOrganization                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    ExchangeServer                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    IMEI                                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsActive                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsAlwaysInternet                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsAOACCapable                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsApproved                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsAssigned                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsBlocked                                Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsClient                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsDecommissioned                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsDirect                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsInternetEnabled                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsMDMActive                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsObsolete                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsSupervised                             Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsVirtualMachine                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastActiveTime                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastClientCheckTime                      Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastDDR                                  Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastHardwareScan                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastInstallationError                    Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastLogonUser                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastMPServerName                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastPolicyRequest                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastSoftwareScan                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastStatusMessage                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastSuccessSyncTimeUTC                   Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastSyncNowRequest                       Property              Microsoft.ConfigurationManagement.ManagementProv...
    LatestProcessingAttempt                  Property              Microsoft.ConfigurationManagement.ManagementProv...
    ManagementAuthority                      Property              Microsoft.ConfigurationManagement.ManagementProv...
    Name                                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    PasscodeResetState                       Property              Microsoft.ConfigurationManagement.ManagementProv...
    PasscodeResetStateTimeStamp              Property              Microsoft.ConfigurationManagement.ManagementProv...
    PhoneNumber                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    PolicyApplicationStatus                  Property              Microsoft.ConfigurationManagement.ManagementProv...
    PrimaryUser                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    PSComputerName                           Property              System.String PSComputerName {get;}
    PSShowComputerName                       Property              System.Boolean PSShowComputerName {get;set;}
    RemoteLockState                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    RemoteLockStateTimeStamp                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    ResourceID                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    ResourceType                             Property              Microsoft.ConfigurationManagement.ManagementProv...
    RetireStatus                             Property              Microsoft.ConfigurationManagement.ManagementProv...
    SerialNumber                             Property              Microsoft.ConfigurationManagement.ManagementProv...
    SiteCode                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    SMSID                                    Property              Microsoft.ConfigurationManagement.ManagementProv...
    SmsProviderObjectPath                    Property              System.String SmsProviderObjectPath {get;}
    Status                                   Property              Microsoft.ConfigurationManagement.ManagementProv...
    SuppressAutoProvision                    Property              Microsoft.ConfigurationManagement.ManagementProv...
    SyncNowStatus                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    Unknown                                  Property              Microsoft.ConfigurationManagement.ManagementProv...
    UserDomainName                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    UserName                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    WipeStatus                               Property              Microsoft.ConfigurationManagement.ManagementProv...

    יום רביעי 24 אפריל 2019 00:02
  •  @Rich Matheisen [Ex-MVP (retired)]

    Here all properties

    PS BW1:\> $devices[0]|gm
    
    
       TypeName: IResultObject#SMS_CM_RES_COLL_BW1001FD
    
    Name                                     MemberType            Definition
    ----                                     ----------            ----------
    Clone                                    Method                System.Object Clone(), System.Object ICloneable....
    CompareTo                                Method                int CompareTo(System.Object obj), int IComparabl...
    ContainsObjectClass                      Method                bool ContainsObjectClass(string type), bool IRes...
    Delete                                   Method                void Delete(), void Delete(Microsoft.Configurati...
    Dispose                                  Method                void Dispose(), void IDisposable.Dispose()
    Equals                                   Method                bool Equals(System.Object obj)
    ExecuteMethod                            Method                Microsoft.ConfigurationManagement.ManagementProv...
    FormatDisplayString                      Method                string FormatDisplayString(string value), string...
    FormatQuery                              Method                string FormatQuery(string baseQuery, bool escape...
    Get                                      Method                void Get(), void Get(Microsoft.ConfigurationMana...
    GetArrayItems                            Method                System.Collections.Generic.List[Microsoft.Config...
    GetEnumerator                            Method                System.Collections.IEnumerator GetEnumerator(), ...
    GetHashCode                              Method                int GetHashCode()
    GetQualifierValue                        Method                System.Object GetQualifierValue(string qualifier...
    GetSingleItem                            Method                Microsoft.ConfigurationManagement.ManagementProv...
    GetType                                  Method                type GetType()
    Put                                      Method                void Put(), void Put(Microsoft.ConfigurationMana...
    SetArrayItems                            Method                void SetArrayItems(string propertyName, System.C...
    SetQualifierValue                        Method                void SetQualifierValue(string qualifierName, Sys...
    SetSingleItem                            Method                void SetSingleItem(string propertyName, Microsof...
    ToString                                 Method                string ToString()
    Item                                     ParameterizedProperty Microsoft.ConfigurationManagement.ManagementProv...
    AADDeviceID                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    AADTenantID                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    ActivationLockBypassState                Property              Microsoft.ConfigurationManagement.ManagementProv...
    ActivationLockBypassStateTimeStamp       Property              Microsoft.ConfigurationManagement.ManagementProv...
    ActivationLockState                      Property              Microsoft.ConfigurationManagement.ManagementProv...
    ADLastLogonTime                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    ADSiteName                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    AMTFullVersion                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    AMTStatus                                Property              Microsoft.ConfigurationManagement.ManagementProv...
    ATPLastConnected                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    ATPOnboardingState                       Property              Microsoft.ConfigurationManagement.ManagementProv...
    ATPOrgId                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    ATPSenseIsRunning                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    CAComplianceEvalTime                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    CAComplianceSetTime                      Property              Microsoft.ConfigurationManagement.ManagementProv...
    CAErrorDetails                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    CAErrorLocation                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    CAIsCompliant                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientActiveStatus                       Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientCertType                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientCheckPass                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientEdition                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientRemediationSuccess                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientState                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientType                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    ClientVersion                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    CNAccessMP                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    CNIsOnInternet                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    CNIsOnline                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    CNLastOfflineTime                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    CNLastOnlineTime                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    CoManaged                                Property              Microsoft.ConfigurationManagement.ManagementProv...
    CurrentLogonUser                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceAccessState                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceCategory                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceOS                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceOSBuild                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceOwner                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceThreatLevel                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    DeviceType                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    Domain                                   Property              Microsoft.ConfigurationManagement.ManagementProv...
    EASDeviceID                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntispywareEnabled                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntispywareSignatureLastUpdateDateTime Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntispywareSignatureLastVersion        Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntivirusEnabled                       Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntivirusSignatureLastUpdateDateTime   Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPAntivirusSignatureLastVersion          Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPClientVersion                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPDeploymentDescription                  Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPDeploymentErrorCode                    Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPDeploymentState                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPEnabled                                Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPEngineVersion                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPInfectionStatus                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastFullScanDateTimeEnd                Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastFullScanDateTimeStart              Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastInfectionTime                      Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastQuickScanDateTimeEnd               Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastQuickScanDateTimeStart             Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPLastThreatName                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPendingFullScan                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPendingManualSteps                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPendingOfflineScan                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPendingReboot                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPolicyApplicationDescription           Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPolicyApplicationErrorCode             Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPPolicyApplicationState                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    EPProductStatus                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    ExchangeOrganization                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    ExchangeServer                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    IMEI                                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsActive                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsAlwaysInternet                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsAOACCapable                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsApproved                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsAssigned                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsBlocked                                Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsClient                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsDecommissioned                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsDirect                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsInternetEnabled                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsMDMActive                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsObsolete                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsSupervised                             Property              Microsoft.ConfigurationManagement.ManagementProv...
    IsVirtualMachine                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastActiveTime                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastClientCheckTime                      Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastDDR                                  Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastHardwareScan                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastInstallationError                    Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastLogonUser                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastMPServerName                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastPolicyRequest                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastSoftwareScan                         Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastStatusMessage                        Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastSuccessSyncTimeUTC                   Property              Microsoft.ConfigurationManagement.ManagementProv...
    LastSyncNowRequest                       Property              Microsoft.ConfigurationManagement.ManagementProv...
    LatestProcessingAttempt                  Property              Microsoft.ConfigurationManagement.ManagementProv...
    ManagementAuthority                      Property              Microsoft.ConfigurationManagement.ManagementProv...
    Name                                     Property              Microsoft.ConfigurationManagement.ManagementProv...
    PasscodeResetState                       Property              Microsoft.ConfigurationManagement.ManagementProv...
    PasscodeResetStateTimeStamp              Property              Microsoft.ConfigurationManagement.ManagementProv...
    PhoneNumber                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    PolicyApplicationStatus                  Property              Microsoft.ConfigurationManagement.ManagementProv...
    PrimaryUser                              Property              Microsoft.ConfigurationManagement.ManagementProv...
    PSComputerName                           Property              System.String PSComputerName {get;}
    PSShowComputerName                       Property              System.Boolean PSShowComputerName {get;set;}
    RemoteLockState                          Property              Microsoft.ConfigurationManagement.ManagementProv...
    RemoteLockStateTimeStamp                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    ResourceID                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    ResourceType                             Property              Microsoft.ConfigurationManagement.ManagementProv...
    RetireStatus                             Property              Microsoft.ConfigurationManagement.ManagementProv...
    SerialNumber                             Property              Microsoft.ConfigurationManagement.ManagementProv...
    SiteCode                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    SMSID                                    Property              Microsoft.ConfigurationManagement.ManagementProv...
    SmsProviderObjectPath                    Property              System.String SmsProviderObjectPath {get;}
    Status                                   Property              Microsoft.ConfigurationManagement.ManagementProv...
    SuppressAutoProvision                    Property              Microsoft.ConfigurationManagement.ManagementProv...
    SyncNowStatus                            Property              Microsoft.ConfigurationManagement.ManagementProv...
    Unknown                                  Property              Microsoft.ConfigurationManagement.ManagementProv...
    UserDomainName                           Property              Microsoft.ConfigurationManagement.ManagementProv...
    UserName                                 Property              Microsoft.ConfigurationManagement.ManagementProv...
    WipeStatus                               Property              Microsoft.ConfigurationManagement.ManagementProv...
    
    

    יום רביעי 24 אפריל 2019 00:02
  • Try this and see if you get an array of names:

    $devices = Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE" | Select -ExpandProperty Name

    The "Name" property isn't a simple string. It looks to be a Microsoft.ConfigurationManagement.ManagementProvider.IResultObject object.

    I don't have a SCCM to work with, so I'm not sure I can be of much more help.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    יום רביעי 24 אפריל 2019 01:26
  • I can try to help, I use SCCM daily.  The output of the Get-CMDevice returns objects that have a Name property, at least in two of my environment.
    יום רביעי 24 אפריל 2019 13:45
  • I just ran the following code and it listed all device names in a collection.  Here is what I did

    1. Opened SCCM console

    2. In the console in the top left corner, select the drop down and select "Connect Via Windows PowerShell ISE"

    3. In the PowerShell ISE that opened, at the end of the code that is auto generated, I entered the following

    $devices = Get-CMDevice -CollectionName "All Systems"
    
    foreach($device in $devices)
    {
        $device.Name
    }

    I hit F5 and I get a list of names in the All Systems collection.  

    יום רביעי 24 אפריל 2019 14:15
  • Try this and see if you get an array of names:

    $devices = Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE" | Select -ExpandProperty Name

    The "Name" property isn't a simple string. It looks to be a Microsoft.ConfigurationManagement.ManagementProvider.IResultObject object.

    I don't have a SCCM to work with, so I'm not sure I can be of much more help.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    I get the list of names when i enter that array. 

    PS BW1:\> $devices2 = Get-CMDevice -CollectionName "Intl Home Worker PCI Subnet" | Select -ExpandProperty Name
    PS BW1:\> $devices2
    YOUWN74880
    YOUWD72873
    YOUWD72865
    YOUWD74346
    YOUWD75196
    YOUWD75198
    YOUWD75199
    YOUWD75197
    YOUWD77254
    YOUWD77253
    YOUWD77220
    PS BW1:\>

    יום רביעי 24 אפריל 2019 15:21
  • I just ran the following code and it listed all device names in a collection.  Here is what I did

    1. Opened SCCM console

    2. In the console in the top left corner, select the drop down and select "Connect Via Windows PowerShell ISE"

    3. In the PowerShell ISE that opened, at the end of the code that is auto generated, I entered the following

    $devices = Get-CMDevice -CollectionName "All Systems"
    
    foreach($device in $devices)
    {
        $device.Name
    }

    I hit F5 and I get a list of names in the All Systems collection.  

    My issue isnt inside SCCM console or SCCM console ISE. It's from the regular powershell prompt. Also we know that it is reading from SCCM, because i am getting the names listed in the errors. So it is reading the device collection just like a list. 

    יום רביעי 24 אפריל 2019 15:22
  • stay with me, in that same code, where you get a list of devices, make it look like below

    $devices = Get-CMDevice -CollectionName "All Systems"
    
    foreach($device in $devices)
    {
        Add-ADGroupMember -Identity "ADGROUPNAMEHERE" -Members $device.Name
    }

    If the above doesn't work, the issue must be with the data types, does -Members look for a string?  $device.Name is a string...

    I would run the Add-AdGroupMember cmdlet in the same powershell session and manually enter the data and see if that works.

    יום רביעי 24 אפריל 2019 15:29
  • That's good!

    Now try this:

    Get-CMDevice -CollectionName "Intl Home Worker PCI Subnet" | 
        Select -ExpandProperty Name | 
            ForEach-Object{ Add-ADGroupMember "ADDGROUPNAMEHERE" -Members $_ }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    יום רביעי 24 אפריל 2019 15:38
  • That's good!

    Now try this:

    Get-CMDevice -CollectionName "Intl Home Worker PCI Subnet" | 
        Select -ExpandProperty Name | 
            ForEach-Object{ Add-ADGroupMember "ADDGROUPNAMEHERE" -Members $_ }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Ran it and I get the same error as before. 

    Add-ADGroupMember : Cannot find an object with identity: 'MILWN74880' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWN74880:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    Add-ADGroupMember : Cannot find an object with identity: 'MILWD72873' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWD72873:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    Add-ADGroupMember : Cannot find an object with identity: 'MILWD72865' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWD72865:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    Add-ADGroupMember : Cannot find an object with identity: 'MILWD74346' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWD74346:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    Add-ADGroupMember : Cannot find an object with identity: 'MILWD75196' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWD75196:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    Add-ADGroupMember : Cannot find an object with identity: 'MILWD75198' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWD75198:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    Add-ADGroupMember : Cannot find an object with identity: 'MILWD75199' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWD75199:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    Add-ADGroupMember : Cannot find an object with identity: 'MILWD75197' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWD75197:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    Add-ADGroupMember : Cannot find an object with identity: 'MILWD77254' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWD77254:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    Add-ADGroupMember : Cannot find an object with identity: 'MILWD77253' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWD77253:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    Add-ADGroupMember : Cannot find an object with identity: 'MILWD77220' under: 'DC=sub,DC=domain,DC=com'.
    At C:\SCCM-ADD-ADGroupMember6.ps1:13 char:25
    + ... ach-Object{ Add-ADGroupMember "SCCM_Intl_Home_Worker_PCI_Subnet" -Mem ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (MILWD77220:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
        + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
     
    

    יום רביעי 24 אפריל 2019 15:58
  • stay with me, in that same code, where you get a list of devices, make it look like below

    $devices = Get-CMDevice -CollectionName "All Systems"
    
    foreach($device in $devices)
    {
        Add-ADGroupMember -Identity "ADGROUPNAMEHERE" -Members $device.Name
    }

    If the above doesn't work, the issue must be with the data types, does -Members look for a string?  $device.Name is a string...

    I would run the Add-AdGroupMember cmdlet in the same powershell session and manually enter the data and see if that works.

    Tested Command ADD-ADGroupMember in same window and it works fine. Also works fine in the Powershell ISE and Regular Powershell windows. 

    I believe you are right on the datatypes. It's having trouble tying the strings together or it could be that the property for " Name " needs to specified for SCCM and then for Active Directory. Not sure how i would do that. But that is something i have explored. 

    OR 

    Else If I could write a script to automatically open the SCCM console powershell window and automatically execute the script that would work too. 

    I figure I will eventually have to figure this issue out. I need to be able work with both SCCM and Active Directory. 

     

    יום רביעי 24 אפריל 2019 16:36
  • That's good!

    Now try this:

    Get-CMDevice -CollectionName "Intl Home Worker PCI Subnet" | 
        Select -ExpandProperty Name | 
            ForEach-Object{ Add-ADGroupMember "ADDGROUPNAMEHERE" -Members $_ }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Rich... I think you might have solved it. I just added an extra " $ " 

    Get-CMDevice -CollectionName "DEVICECOLLECTIONNAMEHERE" | 
        Select -ExpandProperty Name | 
            ForEach-Object{ Add-ADGroupMember -Identity "SCCM_Intl_Home_Worker_PCI_Subnet" -Members $_$ }

    It works!!!! No more error. That one little Select piece with Expand property did it! Now I will Automate it by Schedule to know for sure it works. Thanks for helping figure this out!


    • סומן כתשובה על-ידי Chris480602 יום רביעי 24 אפריל 2019 17:17
    • נערך על-ידי Chris480602 יום רביעי 24 אפריל 2019 17:42
    יום רביעי 24 אפריל 2019 16:43
  • Glad you got it to work, I'm not entirely sure about the $_$ thing, but if it works :)
    יום רביעי 24 אפריל 2019 17:16
  • Glad you got it to work, I'm not entirely sure about the $_$ thing, but if it works :)
    Thanks again. 
    יום רביעי 24 אפריל 2019 17:17
  • I don't know if there's another property in the object returned by Get-CMDevice that holds the samAccountName of the computer. The "name" property looks to be only the CN property of the computer object, and the Add-ADGroupMember want the samAccountName.

    The CN property of a computer object doesn't have the trailing "$", but the samAccountName (being the NetBIOS name of the computer) does. The NetBIOS name must be unique within the AD, but the CN only has to be unique within the organizational unit.

    You might want to look around and see if there is another property with the samAccountName in it. There are a couple that might fit the bill: PSComputerName, and UserName


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    יום רביעי 24 אפריל 2019 17:58