ineedalife
ineedalife

Reputation: 107

output a string then do something and add to the same string

I am trying to write to the console :

Write-Host "Backing up Switch1"

Then run the backup and check if it was successful

Write-Host "Backing up $Building $SwitchName ..."
$initFldrCount =  Get-ChildItem C:\Admin\$SwitchName | Measure-Object | ForEach-Object{$_.Count}
C:\kitty_portable-0.70.0.9.exe -ssh -l Admin -pw Password -cmd $Command $ip 
$count++
Start-Sleep 5
$fnlFldrCount = Get-ChildItem C:\Admin\$SwitchName | Measure-Object | ForEach-Object{$_.Count}
#Make sure a backup was made
if (($initFldrCount + 1) -ne $fnlFldrCount){
    $Status = "Failure"
}
else {
    $Status = "Success"
}
Write-Host "===$Status==="

it then outputs

Backing up Switch-1 ...
===Failure===

But I want it to add failure to the end of the Backing up string after the script

Backing up Switch-1 ...  ===Failure===

How would I go about doing this

Upvotes: 0

Views: 30

Answers (1)

UnhandledExcepSean
UnhandledExcepSean

Reputation: 12804

Simply add the -NoNewLine switch to the line

Write-Host "Backing up $Building $SwitchName ..."

as such:

Write-Host "Backing up $Building $SwitchName ..." -NoNewLine

Upvotes: 2

Related Questions