Passing CSV imported parameters to multiple fuctions

Welcome Forums General PowerShell Q&A Passing CSV imported parameters to multiple fuctions

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 11 months ago.

  • Author
  • #66100

    Points: 32
    Rank: Member

    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

  • #66123

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

  • #66127

    Points: 32
    Rank: Member

    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

  • #66136

    Points: 167
    Helping Hand
    Rank: Participant


    #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     

The topic ‘Passing CSV imported parameters to multiple fuctions’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort