Powershell Script Is Not Providing an Output with The Param Function Also Need the Output in an Excel Sheet

浪尽此生 提交于 2021-02-17 05:20:11

问题


What I am trying to achieve is an excel sheet which will contain the list of machines which are not reachable (current output displayed in the image). When I am trying to run the following script with the function, it's not working. How do I get this to work and implement the output into an excel sheet? I realize it's a two part question but I am new to powershell and I really can't figure this out.

EDIT: Even after entering a path when the console prompts, nothing happens.

OUTPUT: Data Which Needs to be Exported to an Excel Sheet

SCRIPT:

    Param(
  [Parameter(Mandatory=$true)][string]$outFilePath
)


$result=@()

$machineName = "ENC-CAP-COM-01.ee.intern","ENC-CAP-COA-02.ee.intern", "192.168.1.9"
foreach ($t in $machnieName)
{

 if(!(Test-NetConnection -ComputerName $t -InformationLevel Quiet))
    { 
        $a=Test-NetConnection -ComputerName $t -Port 5895 -WarningAction SilentlyContinue

        $result+=New-Object -TypeName PSObject -Property 
        ([ordered]@{
        'Time' = (get-date -Format 'dd\/MM\/yyyy hh:mm')
        'Target'=$a.ComputerName;
        'Status'=$a.PingSucceeded 
        })
    }

}

$result |  Out-File $outFilePath -Encoding utf8 -Append

来源:https://stackoverflow.com/questions/61058923/powershell-script-is-not-providing-an-output-with-the-param-function-also-need-t

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!