Saturday, 15 January 2011

powershell - Append CSV output coding issue -


Hello, I created the script below to audit local administrator groups on remote script. It works fine, but since it only outputs data through all the hosts, I am afraid the array buffer will be out of place before getting the chance to export the CRV, so I am trying to make it Attach the output from each host because it goes through the list, except that I can not display the header on the first line and the editable lines below it I add. When I try to attachment below, I get the output given below. I must be an itemized word header and the other information should be listed in the next line. What am i doing

@ { Server = PC1; Subscribers = Administrators; Distinguished Name = DC = Domain, DC = Com

should look like this. It looks like this if I do not get attached and I make it a CSV after it ends through the list of Hosts

  server member-specific name host 1 administrator; Admin2 DC = DOMAIN, DC = COM $ server = get-content "C: \ script \ ad audit \ local admin \ workstation .txt" $ output = "c: \ Temporary local administrator audit $ CurrentDate.csv" $ result = @ () $ Disconnected = "No" Respond to foreign currency ($ server in server $ server) {$ connected = test-connection $ server-number 1 -quiet if ($ connect) {"$ server response" | Out-File- "C: \ Temporary Local Admin Goodhostes $ Current DataTax"} and {"$ server did not respond". Out-File-Aided "c: \ temp \ LocalAdmin badhosts $ CurrentDate.txt"} $ group = [ADSI] "WinNT: // $ server / admin" $ members = $ group.Members () | InvachMember ("name", 'GetProperty', $ null, $ _, $ null)} $ result + = new object PsObject -Property @ {DistinguishedName = (get-adcomputer ($ server)) -properties * | Select Distinguished Name). Specified Name Server = $ Server Member = $ Member-Joa ";" } $ Results | Export-CSV $ Output -Nautemapation} `  

if ($ connect - $ true) {new-object PSObject-property @ {Distinguishing Name = (Get-ADComputer $ _) .DistinguishedName Server = $ _ Members = $ member-whatever ";" }} And {write-host "}"

My suggestion is to use pipelines Instead of a novel statement, so the file on each object file is written as soon as possible.

  $ server | $ $ For every object Connect = test-connection $ _- number 1 -Quiet -ErrorAction SilentlyContinue $ state = if ($ is connected) {"$ _ replied"} and {"$ _ did not respond" } $ State | Out-File - Append "c: \ temp \ LocalAdmin goodhosts $ CurrentDate.txt" $ group = [ADSI] "WinNT: // $ _ / admin, group" $ members = $ group.Members () | If ($ connect) {new object PSObject -Property @ {DistinguishedName = (get-adcomputer $ _). Specific domain name = $ _ members = $ member-included ";" }}} | Export-CSV $ Output- Any Type Information    

No comments:

Post a Comment