Natively, PowerShell
provides for outputting data in text format or as a CSV file. Exporting data as it would appear onscreen
to a text file is as simple as piping the data to Out-File and specifying the filename:
Out-File [-filePath] < string > [[-encoding] < string > ] [-append] [-width < int > ] [-
inputObject < psobject > ] [-force] [-noClobber] [-whatIf] [-confirm]
[ < CommonParameters > ]
The filePath parameter is positional so without any switches Out-File expects to
have information piped to it and a filePath value provided which will be the file
written. The noClobber switch specifies that if there is a file with the name
specified in the filePath it will not overwrite the contents as is the default
behavior for the cmdlet. Using the encoding parameter the file being written can be
encoded in several different format by choosing Unicode, UTF7, UTF8 or ASCII.
To write a file with a list of all mailboxes in an Exchange organization you would simply run:
Get-Mailbox | Out-File C:\data\allmailboxes.txt
You could then open that file in a text editor for reference. But what if you have a complex set of data
that you want to perform analysis against? You could take that text file and massage it until it worked in
Excel or you could use simply the Export-Csv cmdlet. The Export-Csv file has the following syntax:
Export-Csv [-path] < string > -inputObject < psobject > [-force] [-encoding < string > ]
[-noTypeInformation] [-noClobber] [-whatIf] [-confirm] [ < CommonParameters > ]
Export-Csv has syntax similar to the Out-File cmdlet except it has the noTypeInformation switch,
which removes the first line of the exported CSV file which, by default, is the type of object that was
exported to the file.
Pages:
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652