问题
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