Nope, I tried that. I build my path based on cancatination of instance name and previous variable $Path1 that I get initially in the same script, like so:
[string]$MyPath="\\" + $Servername + "\" + $Path1.value.Replace(":\","$\") + "DBBackup.txt" But nothing gets logged. If I execute this stored procedure from a job I get a nice output file that looks like
Processed 440 pages for database 'MyDB'...etc
I load sql assembly like and create an object this
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null $SQLserver = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $Servername
# Create Databases object
$dbs = $SQLserver.Databases
#Here I execute my stored proc
#then I want to iterate through dbs and log backup status for each database:
foreach ($db in $dbs) { Write-Debug "Backing up $db.Name on $Servername "
if ($?) {"Successfully backed up " + $db.Name + " to " + $Path.value | Out-File -filepath $logFile -encoding oem}
else {"Failed to back up " + $db.Name + " to " + $serverBackup.File | Out-File -filepath $logFile -encoding oem} }
But the only this that gets logged is
Successfully backed up tempdb to C:\MyPathHere