Passing CSV imported parameters to multiple fuctions

Hello experts,

Being a newbie to Powershell, seeking advise from you…!

I’m a wintel support guy and looks after hundreds of servers running equal number of applications. my day in office starts with healthcheck of servers by looking applications services, disk space, URL status, scheduled job status …etc. to make my job easy, i’m thinking to automate health check report using Powershell.

I have Server inventory sheet which contains ServerName, ServiceType, Prod/Dev Env…etc.
ServerName ServiceType Prod/Dev Env
Svr01 App1 Prod
Svr02 App1 Dev
Svr03 App2 Prod
Svr04 App3 Prod

My question is, by importing CSV file, how do I pass multiple parameters to multiple functions to get healthcheck report for disk, application service status (many servers have specific application service name), last reboot…etc…

Expected output

Disk Information:
ServerName ServiceType Device ID Total Size, free Space
Svr01 App1 C: 100 10

Service Status:
ServerName App ServiceName Status Env
Svr01 AppService1 Running Prod
Svr02 AppService2 Stopped Prod
Svr03 AppService3 Running Prod

Thanks in Advance

You would write a script.

Read through our free book (eBooks menu) on Creating HTML Reports in PowerShell. It walks through a very similar, simplistic example of this, including producing an HTML-formatted report at the end.

Thanks Don for prompt response.

Below is the piece of code where I get output for single/first server only…How do I pass array to function? so that I can get output for all servers listed in CSV…

someting like

MyFuntion ($Server, $envt, App)

$csvPath = ‘F:\MyDocs\MyScripts\ServerMonitoring\TPAServerInventory.csv’

$Serverinv = Import-Csv -Path $ScrPath

foreach ($record in $Serverinv)
$Server = $($record.ServerName)
$Envt = $($record.Environment)
$App = $($record.ServiceType)

Function ChkSrv()
$servicechk = @()
foreach ($svr in $Server)
if ($App -eq ‘Cognos’)
$Stat = Get-Service -ComputerName $server -Name ‘IBM Cognos 10’ | select Name, Status
$objsrv = New-Object psobject
Add-Member -InputObject $objsrv -membertype noteproperty -name ServerName -value $Server
Add-Member -InputObject $objsrv -membertype noteproperty -name Servicename -value $stat.Name
Add-Member -InputObject $objsrv -membertype noteproperty -name Status -value $Stat.Status
$servicechk += $objsrv


Return $servicechk

chksrv | Format-Table -AutoSize


ServerName ServiceName Status

SRV01 IBM Cognos 10 Running


#region Input
$csvPath = '.\TPAServerInventory.csv' # Columns: ServerName,ServiceName,Env

#region Process
$Report = foreach ($Server in (Import-Csv $csvPath)) {
    New-Object -TypeName PSObject -Property @{
        ServerName    = $Server.ServerName 
        ServiceName   = $Server.ServiceName
        ServiceStatus = $(
            try {
                (Get-Service -ComputerName $Server.ServerName -Name $Server.ServiceName -ErrorAction Stop).Status
            } catch {
        Environment   = $Server.Env
    } | select ServerName, ServiceName, ServiceStatus, Environment # to order output columns

#region Output
$Report | Format-Table -AutoSize

Sample output:

ServerName ServiceName ServiceStatus Environment
---------- ----------- ------------- -----------
localhost  WwanSvc           Stopped Prod       
localhost  wudfsvc           Running Dev        
localhost  App2         DoesNotExist Prod