Issues with output to files

Hi Everyone,

I have a script that is set up to remediate servers that windows updates did not complete on. Part of my script is set to not work on certain servers and put these servers into certain lists for manual intervention. These lists should only include the name of the server so that the entire list can be copied to another application.

Part of the Script

$logdate = (Get-Date -UFormat ".%a %m-%d-%Y %H-%M.%S %p")
$logs = new-item -path $LogFolder -Name "$Environment Automated Update Remediation Results$logdate.log"

$SQLFolder = "$Basefolder\SQL"
$Exists = Test-Path -Path $SQLFolder
if ($Exists -eq "True") {
    Write-Host "Directory Exists!"
} else {
    New-Item -Path $SQLFolder -ItemType directory
}

$logdate = (Get-Date -UFormat ".%a %m-%d-%Y %H-%M.%S %p")
$SQL = new-item -path $SQLFolder -Name "$Environment SQL Servers Needing Manual Remediation$logdate.log"
Add-Content -path $SQL -Value "$(Get-Timestamp) This is a list of the SQL servers that will need to be remediated manually"

$ManualFolder = "$Basefolder\Manual_Remediation"
$Exists = Test-Path -Path $ManualFolder
if ($Exists -eq "True") {
    Write-Host "Directory Exists!"
} else {
    New-Item -Path $ManualFolder -ItemType directory
}

$logdate = (Get-Date -UFormat ".%a %m-%d-%Y %H-%M.%S %p")
$Manual = new-item -path $ManualFolder -Name "$Environment Servers Needing Manual Remediation$logdate.log"
Add-Content -path $Manual -Value "$(Get-Timestamp) This is a list of the servers that will need to be remediated manually"

$ListOfServers = Get-content -path "Path to list of servers"

$ListOfServers | Foreach-Object -ThrottleLimit 25 -Parallel {
    if ($_ -like '*SQL*'){
        Add-Content -path $using:SQL -Value "$_"
    } Elseif ($_ -like '*FTP*'){
        Add-Content -path $using:Manual -Value "$_"
    }
}

The output that we are getting

@{Servername=SQLServer1}

The output we are expecting

SQLServer1

Hi,

Maybe something like this ?

$ListOfServers | Foreach-Object{
    if ($_.values -like '*SQL*'){
        Add-Content -path $using:SQL -Value "$($_.values)"
    } Elseif ($_.values -like '*FTP*'){
        Add-Content -path $using:Manual -Value "$($_.values)"
    }
}

Thanks DejvDzi, I was able to use what you proposed with a tweak. What eventually worked was for me to use ServerName instead of Values.