Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
function log-file {
  Add-Content -path $logfile -Value "$(Get-Date) $message"

function ping-server {
  $ping = New-Object System.Net.NetworkInformation.Ping

log-file "Pinging server = " + (ping-server $server).status

How can I get the above to work with one line rather than doing this:

$pingable = (ping-server $server).status
log-file "Pinging server = $pingable"
share|improve this question

1 Answer 1

Try making this modification to the log-file function call

log-file $("Pinging server = " + (ping-server $server).status)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.