powershell - Why does Add-Member think every possible property already exists (on a Microsoft.ActiveDirectory.Management.ADUser object)? -
so, helping out in question on serverfault , ran odd behaviour.
if object of microsoft.activedirectory.management.aduser
type, such through get-aduser
, whenever try add noteproperty
using add-member
, following situation:
ps c:\users\someuser> $u = get-aduser someuser ps c:\users\someuser> $u | add-member ldskfjlkdsfj dfklsjdflkdsjf add-member : cannot add member name "ldskfjlkdsfj" because member name exists. overwrite member anyway, add force parameter command. @ line:1 char:6 + $u | add-member ldskfjlkdsfj dfklsjdflkdsjf + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : invalidoperation: (cn=someuser,...example,dc=com:psobject) [add-member], invalidoperationexception + fullyqualifiederrorid : memberalreadyexists,microsoft.powershell.commands.addmembercommand
using -force
parameter allow me "overwrite" bogus property, object makes act has every property?
trying access property (even 1 not added) returns nothing, rather throwing exception i'd expect. setting property possible, although "regular" powershell object imagine shouldn't be.
ps c:\users\someuser> $u = get-aduser someuser ps c:\users\someuser> $u.bogus ps c:\users\someuser> $u.fishy ps c:\users\someuser> $u.fishy = "fish" ps c:\users\someuser> $u.fishy fish ps c:\users\someuser>
i'm not sure if matters, behaviour seen me on windows server 2012 r2 powershell 4.0.
this because ad objects "special" , act weirdly when comes extended properties. can read more in question, messes pipeline binding.
in case, think due add-member
testing existence of specific property (which on ad object true if property 1 made , has no value).
you've seen when testing various property names , assigning them.
you should able use add-member -force
make work though.
Comments
Post a Comment