powershell - Referencing variable in scriptblock -


i have following code parsing xml file in powershell, , iterating through entries in config file (which backup jobs) , performing backups (by calling functions).

if ($xmlfile.configuration.dbandfilesbackup.item("mssql").haschildnodes) {     $xmlfile.configuration.dbandfilesbackup.mssql.backup |          start-rsjob -name {$_.name} -throttle 2  -scriptblock {             # begin backup             beginbackup $_.name $log              # backup mssql database             mssqlbackup $_.name $_.dbpath $using:backupdir $using:backuptempdir              # backup files             filesbackup $_.name $_.foldername $_.filespath $using:backupdir $using:backuptempdir              # end backup             endbackup $_.foldername $_.name $log $using:emailto $using:backupdir $using:backuptempdir         } -functionstoload beginbackup,mssqlbackup,filesbackup,endbackup,mailer,printheader |         wait-rsjob |         receive-rsjob |         out-file "$scriptdir\logs\corebackup\$scriptname $($xmlfile.configuration.dbandfilesbackup.mssql.backup.name) $datestamp.log" } 

start-rsjob custom powershell module similar start-job cmdlet handles kicking off parallel jobs.

both rsjob , native powershell start-job cmdlet don't seem handle powershell transcription (logging). i'm utilizing write-output, in addition out-file capture output of jobs.

the problem i've run in write-output portion of script want include name of backup in log file name. in other words end file named "corebackup 2015-08-24.log" instead of "corebackup backupname 2015-08-24.log".

the issue how pass $_.name out-file. right log written, without job name.

try this:

start-rsjob -argumentlist @($name) -throttle 2 -scriptblock {     $name = $args[0]     ... } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -