![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Getting Deleted Object info with Powershell I've given up on trying to get "Deleted Object" info with VBScript and have figured out (the basics) on how to get this info using Powershell. However, I need to be able to get complete info on on properties. What I'm running into is some properties like objectsid look to be arrays and when I try to list it ie $result[0].properties.objectsid I get 28 lines of broken up sid values. I'm obviously new at this and don't know a lot about Powershell especially when it comes to formating this type of output. What I ultimately want to do is pipe a complete list of deleted objects and all of the properties to html, excel, csv or even text but can't get it to work. Here's what I have so far... $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() $root = $dom.GetDirectoryEntry() $root.psbase.AuthenticationType =[System.DirectoryServices.AuthenticationTypes]::FastBind $root.psbase.path ="LDAP://cn=Deleted Objects," + $root.distinguishedname $search = [System.DirectoryServices.DirectorySearcher]$root $search.Filter = "(&(isDeleted=TRUE)(objectclass=user))" $search.tombstone = $true $search.SearchScope = [System.DirectoryServices.SearchScope]::OneLevel $result = $search.Findall() $result I've had some success with: for ($a = 0; $a -le $result.count; $a++) {$result[$a].properties} but can't get it to go to html or csv and I've also noticed that some of the output on some fields are not outputting all of the data, fields like name, cn, adspath are all truncated with "..." Any assistance would be greatly appreciated. |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Getting Deleted Object info with Powershell
$result|get-member Do these work: $result|out-file -filepath out.tmp -encoding ascii $result|format-table -autosize Marco | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Getting Deleted Object info with Powershell $result|get-member produces this: TypeName: System.DirectoryServices.SearchResult Name MemberType Definition ---- ---------- ---------- Equals Method System.Boolean Equals(Object obj) GetDirectoryEntry Method System.DirectoryServices.DirectoryEntry GetDirectoryEntry() GetHashCode Method System.Int32 GetHashCode() GetType Method System.Type GetType() get_Path Method System.String get_Path() get_Properties Method System.DirectoryServices.ResultPropertyCollection get_Properties() ToString Method System.String ToString() Path Property System.String Path {get;} Properties Property System.DirectoryServices.ResultPropertyCollection Properties {get;} And $result|out-file -filepath out.tmp -encoding ascii And $result|format-table -autosize Do not render all fields and both have truncated output. "Marco Shaw [MVP]" wrote:
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||
| Guest | Re: Getting Deleted Object info with Powershell FYI, You can force the results of objectsid to a one line string: PS> "$($result[0].properties.objectsid)" 1 5 0 0 0 0 0 5 21 0 0 0 87 181 4 70 209 130 90 168 141 67 81 39 149 4 0 0 ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Getting Deleted Object info with Powershell A couple of things here ##### You don't need the next two lines... [ADSI]"" effectively does the same thing $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() $root = $dom.GetDirectoryEntry() $root = [ADSI]"" ##Use something like this ##### Unless you specifically want FastBind. Not sure why you do this $root.psbase.AuthenticationType=[System.DirectoryServices.AuthenticationTypes]::FastBind $root.psbase.path ="LDAP://cn=Deleted Objects," + $root.distinguishedname ### Generally I find it easier to setup the DirectorySearch in the constructor, but thats just me ![]() ## $search = new-object System.DirectoryServices.DirectorySearcher($root,$filter) $search = [System.DirectoryServices.DirectorySearcher]$root $search.Filter = "(&(isDeleted=TRUE)(objectclass=user))" $search.tombstone = $true $search.SearchScope = [System.DirectoryServices.SearchScope]::OneLevel $result = $search.Findall() $result The reason you dont get anything back is because $result is an array of System.DirectoryServices.SearchResult try # im on the bus so I can tell you specifically if it works $result | foreach{$_.Properties} "Like_Wise" <LikeWise@xxxxxx> wrote in message news:2121AFEF-D55B-4F92-A7D0-42A0FF740370@xxxxxx
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #6 (permalink) | ||||||||||||
| Guest | Re: Getting Deleted Object info with Powershell btw... if your truncating fields in the out-file you can use the -width out-file $file -enc ASCII -width 500 "Like_Wise" <LikeWise@xxxxxx> wrote in message news:BCD8191F-A5E6-42E1-967E-487F174CAAE3@xxxxxx
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #7 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Getting Deleted Object info with Powershell To *disable* truncated properties value:
Shay Levi $cript Fanatic http://scriptolog.blogspot.com Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #8 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Getting Deleted Object info with Powershell I'm not sure that a csv file is the candidate since the user properties contains a lot of comma characters. Check this one too: ($result[0].Properties | ft -auto -wrap) > .\test.txt ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #9 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: Getting Deleted Object info with Powershell if you use export-csv it will take the entire value and wrap it in "" so the internal , wont matter. Brandon Shell --------------- Blog: http://www.bsonposh.com/ PSH Scripts Project: www.codeplex.com/psobject SL> I'm not sure that a csv file is the candidate since the user SL> properties contains SL> a lot of comma characters. SL> Check this one too: SL> ($result[0].Properties | ft -auto -wrap) > .\test.txt SL> SL> ----- SL> Shay Levi SL> $cript Fanatic SL> http://scriptolog.blogspot.com SL> Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
| ||||||||||||||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||||||||||||||
| | #10 (permalink) | |||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: Getting Deleted Object info with Powershell Thanks! ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
SL>> properties contains SL>> a lot of comma characters. SL>> Check this one too: SL>> ($result[0].Properties | ft -auto -wrap) > .\test.txt SL>> ----- SL>> Shay Levi SL>> $cript Fanatic SL>> http://scriptolog.blogspot.com SL>> Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
| |||||||||||||||||||||||||||||||||||||||||||