Is it possible to return variable ($logstring) from the ScriptCommand to feed into the LogWriter function?
$ScriptCommand = "`$Cert = Get-ChildItem Cert:\LocalMachine\My | where {`$_.thumbprint -eq `"$TP`"}
if(`$Cert.FriendlyName -eq `"$FriendlyName`")
{
`$logString = `"Friendly Name already $FriendlyName on $Node.`"
}
else
{
`$Cert.FriendlyName = `"$FriendlyName`"
}"
$CommandScriptBlock = [Scriptblock]::Create($ScriptCommand)
Invoke-Command -ComputerName $Node -ScriptBlock $CommandScriptBlock
LogWriter -LogFile $Lfile -LogString $logString
$logString =.$CommandScriptBlock = { $cert = Get-ChildItem ... }That way you don't need the backticks escaping everywhere and your IDE will see errors (since you work with code rather than a string) and auto-format.