In Powershell -- Export object to textfile in custom format -
since, beginner, 've no hands-on powershell programming.although had script developed insert data array csv file follows:
#following array $inventoryreport = new-object -typename psobject -property @{ computername = "1mycomputername" domainname = "2mycomputerdomain" manufacturer = "3mycomputermanufacturer" } #now export data csv, using following: $inventoryreport |select-object -property computername, domainname, manufacturer | export-csv -path "c:\abc.csv" -notypeinformation -erroraction stop #this works fine
and output of above :
"computername","domainname","manufacturer" "1mycomputername","2mycomputerdomain","3mycomputermanufacturer"
.... now, don't want , want ouput appear in columnar fashion i.e.
"computername","1mycomputername" "domainname","2mycomputerdomain" "manufacturer","3mycomputermanufacturer"
what code changes should done achieve this. ?
either want csv, have, or want custom txt-file. if want latter, try this:
$comp = gwmi win32_computersystem @" "computername","$($comp.name)" "domainname","$($comp.domain)" "manufacturer","$($comp.manufacturer)" "@ | out-file test.txt
sample of test.txt output below. i've got non-domain, custom built pc, don't worry values.
"computername","graimer-pc" "domainname","workgroup" "manufacturer","system manufacturer"
edit suggest learn csv is. remember csv not fileformat, it's formatting-style used in normal textfile. .csv
extension cosmetic let people know textfile uses csv-style. check out wikipedia , technet
in csv file, each object represented comma-separated list of property values of object. property values converted strings (by using tostring() method of object), represented name of property value. export-csv not export methods of object.
the format of exported file follows:
-- first line of csv file contains string '#type ' followed qualified name of object, such #type system.diagnostics.process. suppress line, use notypeinformation parameter.
-- next line of csv file represents column headers. contains comma-separated list of names of properties of first object.
-- additional lines of file consist of comma-separated lists of property values of each object.
Comments
Post a Comment