properties - Powershell Get property 2 levels down -


How it's going to flackoverstow,

I'm new to powershell and the properties seem to be re There is a problem obtaining two levels below the source (aka: I can get the property property like $ foo.bar, but said property is not property such as $ foo.bar.soap)

I have $ Code = [param (mandatory = $ incorrect)] $ output = ".. OrphanedGPTs.txt", [parameter (mandatory = $ incorrect)] $ domain = [system. DirectoryServices.ActiveDirectory.Domain] :: GetCurrentDomain ()) $ strGCPath = "LDAP: //" + $ Domain.Name $ oCmd = new-object -ComObject ADODB.command $ oConnection = new-object -ComObject ADODB.Connection $ oConnection .Provider = "ADsDSOObject" $ oConnection.Open ("Ad Provider") $ oCmD.ActiveConnection = $ oConnection $ strADOQuery = "& lt;" + $ StrGCPath + "& gt ;; (objectCategory = group); distinguishedName; subtree" $ oCmd .CommandText = $ stradOQuery $ TopLevel = $ oCmd.Execute () # This works $ fields = $ oRecordSe T Kfild # it Works $ name = $ field .name # This work does not seem to be $ $ TopLevel.MoveNext () $ TopLevel #this works Write-Output "---------------- - -------- "$ fields # write this work-output" ----------------------- "$ name # this anything Do not Write Returns - Output "-----------------------" $ TopLevel.Fields.Name # Do not Write It Out-Output "----- ---- -------------- "

Which of the following output is below Is:

  Properties: System .__ com object AbsolutePosition: 2 ActiveConnection: System .__ ComObject BOF: Wrong Bookmark: 1 CacheSize: 1 CursorType: 3 EOF: Wrong Fields: System .__ ComObject LockType: 1 MaxRecords: 0 RecordCount: 932 Source: & lt; LDAP: //company.com>;; (ObjectCategory = group); Famous name; Subdivision Full Page: 1 editing mode: 0 Filter: 0 Pejkount: 94 Pejasistm: 10 Sort: Status: State 0: 1 cursor location: 2 Marshall options: 0 Data source: System .__ com object activated Command System .__ com Object StayInSync: Correct Datamember: Index: ----------------- - Properties: System .__ ComObject ActualSize: 234 Properties: 32 DefinedSize: 4000 Name: distinguishedName type : 202 Price: CN = empty, OU = empty, OU = empty group, DC = company, DC = com Precision: 255 points: 255 original price: int Value Value: Data Format: Status: 0 ----------------------- -------------- ----- ---- -----------------------  

If the code works like I wanted to do this , "Reputable name" or something should have been printed between the bottom lines

How can I get $ topLevel.Fields.Name? Firstly, let me indicate that when you can use PowerShell on the COM object,

it is usually a better choice, and in this case, it is ActiveDirectory module:

  Import-module ActiveDirectory Get-ADDomain  

this module The complete documentation can be found. But, let's answer your question. Generally, your syntax will work, but not for COM properties. For example, you can do this:

  $ TopLevel.Fields.Count returns back to my computer  

But the name is COM property, Therefore you need to use the Select-Objects :

  $ TopLevel.Fields | Selection object * Properties: System .__ ComObject ActualSize: 194 Properties: 32 DefinedSize: 4000 Name: distinguishedName Type: 202 Price: CN = Exchange Organization Administrator, OU = Microsoft Exchange Protection Group, DC = XXXXXXXX, DC = XXX Precision: 255 NumericScale: 255 OriginalValue: UnderlyingValue: DataFormat: status: 0  
TopLevel.Fields.Name to get your specific questions

so, to answer ($ how), you do this Will:

$ name = $ TopLevel.Fields | Select-object-expandparty name

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -