Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8658173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:42:00+00:00 2026-06-12T15:42:00+00:00

I have a script that runs from a domain server and ‘does work’ on

  • 0

I have a script that runs from a domain server and ‘does work’ on a domain server.

The work is divided up into jobs that are in scriptblocks that are called with invoke-command using a stored PSsession.

Results are logged on the domain server in a log file that includes a datetime stamp in the logfile name.

Now, I need to add another log that needs to reside on the remote on which the work is done. The log name format also needs to include a date and time stamp.

My problem is passing the name of the log to each of the jobs so that they write to the same file. I’ve played around with -ArgumentList, @args, and $args which I can get to run without errors but do nothing so I am not passing the logfile name correctly.

Below is a super simplified version of how I’ve structured my script.

Is it a mistake to nest the Start-Job in another script block? How would I pass my unique log file name to a number of these scriptblocks to capture success/failure and specific points?


#log file names, ps session and other variables declared here  

  $DoDomainWorkScriptBlock = {

    Try {

            start-job -name DoDomainWorkjob -scriptblock{

          $command = "C:\Program Files\someprogram\someprogram.exe"

          & $command  -f someargs


            If ($? -ne "True") {Throw 'Do work failed’}

            " Do non-domain work job completed. "

            }

        } Catch {$Error[0] | Out-File $ErrorLog -Append}

    }

#other jobs nested in other scriptblocks like the one above here

Invoke-Command -session $RemoteSession -scriptblock $DoDomainWorkScriptblock | Out-File $DomainProgressLog -Append

Invoke-Command -session $RemoteSession -command{Wait-Job -name DoDomainWorkjob } | Out-File $DomainProgressLog -Append

Invoke-Command -session $RemoteSession -command{Receive-Job -Name DoDomainWorkjob } | Out-File $DomainProgressLog –Append


#invoke start, wait, and receive job commands for the other jobs
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:42:02+00:00Added an answer on June 12, 2026 at 3:42 pm

    You can pass arguments to script blocks like this:

    $code = {
      param( $foo )
      Write-Host $foo
    }
    
    $bar = "bar"
    Invoke-Command -ScriptBlock $code -ArgumentList $bar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a shell script that runs on my server every day. It does
I have a script that runs a stored procedure in my SQL server database,
I have a script that runs from a newly created shell. OS is Red
I have an R script that runs just fine when I run it from
I have a content script that runs from my chrome extension. this script injects
I have a T-SQL script that runs every weekday. The script does a lookup
I have a script that runs every two minutes for a Tweet-getter application. In
I have a script that runs every minute at XX:00. The script loops over
I have a script that runs at evening, it writes to a log file
I have a python script that runs a program, which generates few .exe files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.