How do I output the function call to a CSV file for review?

function Get-ServerInfo {
<#
.SYNOPSIS
Uses WMI to retrieve details from one or more servers.

.DESCRIPTION
Get-ServerInfo retrieves several pieces of information from one
or more remote servers.

.PARAMETER computername
One or more computer names to query. Accepts pipeline input.

.PARAMETER logfile
Defaults to failed.txt; will contain the names of computers
that have failed. This file is cleared each time you run
Get-ServerInfo.

.EXAMPLE
This example illustrates how to read a file containing one
computer name per line, and then format the results as a table.
Get-Content names.txt | Get-ServerInfo | Format-Table

.EXAMPLE
This example shows how to query just one computer.
Get-ServerInfo -computername SERVER-R2

.EXAMPLE
This example queries all computers in the SERVERS OU of
the AD domain Company.Com

Import-Module ActiveDirectory
Get-ADComputer -filter * `
  -searchbase 'ou=servers,dc=sleepmed,dc=md' |
  Select -expand Name | Get-ServerInfo
#>

    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True,
                   ValueFromPipeline=$True,
                   ValueFromPipelineByPropertyName=$True)]
        [Alias('name')]
        [string[]]$computername,
        [string]$logfile = 'failed.txt'
    )
    BEGIN {
        Del $logfile -ea SilentlyContinue
    }
    PROCESS {
        foreach ($computer in $computername) {
            $continue = $true
            try {
                $os = Get-WmiObject -class Win32_OperatingSystem `
                 -computer $computer -ea Stop
            } catch {
                $computer | out-file $logfile -append
                $continue = $false
            }
            if ($continue) {
                $bios = Get-WmiObject -class Win32_BIOS `
                 -computername $computer
                $proc = Get-WmiObject -class Win32_Processor `
                 -computername $computer | Select -first 1
                $hash = @{
                    'ComputerName'=$computer;
                    'BIOSSerial'=$bios.serialnumber;
                    'OSVersion'=$os.caption;
                    'OSBuild'=$os.buildnumber;
                    'SPVersion'=$os.servicepackmajorversion;
                    'OSArch'=$os.osarchitecture;
                    'ProcArch'=$proc.addresswidth
                }
                $obj = New-Object -TypeName PSObject -Property $hash
                Write-Output $obj
            }
        }
    }
}

Import-Module ActiveDirectory
Get-ADComputer -filter * `
  -searchbase 'ou=servers,dc=company,dc=com' |
  Select -expand Name | Get-ServerInfo | Export-csv C:\Scripts\ServerDetails.csv
CuriousMAUserAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
Not sure what you're asking.  The last line of this already outputs to .CSV.
Import-Module ActiveDirectory
 Get-ADComputer -filter * `
   -searchbase 'ou=servers,dc=company,dc=com' |
   Select -expand Name | Get-ServerInfo | Export-csv C:\Scripts\ServerDetails.csv 

Open in new window

The function Get-ServerInfo outputs objects, after that you can handle the object however you'd like.
0
CuriousMAUserAuthor Commented:
I understand. The output is empty. I'm trying to output the servers os architecture information to prepare to migrate necessary 2003 servers to 2008 R2. Something appears out of sink. Any thoughts?

 'ComputerName'=$computer;
                    'BIOSSerial'=$bios.serialnumber;
                    'OSVersion'=$os.caption;
                    'OSBuild'=$os.buildnumber;
                    'SPVersion'=$os.servicepackmajorversion;
                    'OSArch'=$os.osarchitecture;
                    'ProcArch'=$proc.addresswidth
0
footechCommented:
Just tested it and it's working fine.  As long as your -searchbase is correct so that Get-ADComputer is returning results then you should be fine.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.