PowerShell using start job to run multiple code blocks at the same time

I will be working with many 1000’s of names in a list preforming multiple function on each name for test labs.
I notice when it is running the functions on each name I am using almost no CPU or memory.  That led me to research can I run multiple threads at once in a PowerShell program. That lead me to articles suggesting start-job would do just want I am looking
for. 
As a test I put this together.  It is a simple action as an exercise to see if this is indeed the best approach.  However it appears to me as if it is still only running the actions on one name at a time.
Is there a way to run multiple blocks of code at once?
Thanks
Start-Job {
$csv1 = (Import-Csv "C:\Copy AD to test Lab\data\Usergroups1.csv").username
foreach ($name1 in $csv1) { Write-Output "Job1 $name1"}
Start-Job {
$csv2 = (Import-Csv "C:\Copy AD to test Lab\data\Usergroups2.csv").username
foreach ($name2 in $csv2) { Write-Output " Job2 $name2"}
Get-Job | Receive-Job
Lishron

You say your testing shows that you are using very little cpu or memory in processing each name, which suggests that processing a single name is a relatively trivial task.  
You need to understand that using a background job is going to spin up another instance of powershell, and if you're going to do that per name what used to require a relatively insignificant amount of memory is going to take around 60 MB.  
Background jobs are not really well suited for multi-threading short-running, trivial tasks.  The overhead of setting up and tearing down the job session can be more than the task itself.
Background jobs are good for long-running tasks.  For multi-threading short, trivial tasks runspaces or a workflow would probably be a better choice.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

Similar Messages

  • Problem running multiple folder actions at the same time

    Hi,
    Does anyone have some experience running multiple folder actions at the same time?
    I've written a Applescript folder action that processes some files. When adding some files, the script starts and all goes well. The processing of each file takes a few minutes, but all files are processed correctly.
    However, when adding some new files to the dropfolder, while the folder action is all ready processing other files dropped a few minutes earlier, the process that is all ready running immediately aborts and the folder action is relaunched on the new files, leaving the old files for what they are...
    The same problem occurs with multiple folders, each having a folder action attached. When dropping files in "Folder A", the script starts processing. But if someone droppes files in "Folder B", The script of folder A aborts, and the script of folder B starts processing. When adding more files to the folders, the result is the same. In some casses, when the last dropped files are processed, the os continues where the operation was aborted on the previous files. But this not always happens. To make things worse, when you remove the items from the folders afterwords, the folder actions starts running again on items no longer present in the folder !!!!
    Does anyone know how I can prevent the folder action being aborted when new files are dropped and placing the new files in "Hold", until the previous files are processed? How can I prevent a folder action being aborted when a item is dropped into another folder?
    I've written a small script to test this behaviour. Just create one or more folders and attach the script below. Drop a item into the folder, wait a few seconds and drop another one in the same or another folder. To monitor what happens please check the console.
    on adding folder items to this_folder after receiving added_items
              set FolderName to this_folder as string
              set ItemName to added_items as string
              repeat with theIncrementValue from 1 to 15
      delay 2
                        do shell script ("logger \"Folder: " & FolderName & "  -  Item: " & ItemName & "  -  Step: " & theIncrementValue & "\"")
              end repeat
              do shell script ("logger \"Folder: " & FolderName & "  -  Item: " & ItemName & "  -  Done...\"")
    end adding folder items to
    Thanks for any feedback.

    That is pretty much the way Folder Actions work, especially since AppleScript is not multi-threaded.  If you are using them as some intermediate step in a workflow, you might rethink the way you are handling the files (for example, use a droplet instead).  Other options would be using launchd to watch a path or a shell script on a different thread.

  • Running multiple DAQ tasks at the same time

    I am trying to setup a program that would allow me to run different analog voltage waveforms on different channels.
    The rate at which samples hit each channel can be the same for all 32, but I want each to be sourced by an individual file I/O source.
    I saw the multiple tasks thread and I did try doing the multiple task approach first and needless to say got the same error.
    Saw something about software timed approach working better, but it is still a bit unclear in that post. Can i do with this card what I described above and if so is this software timing approach the way to go?
    Thanks in advance!

    Hi,
    What DAQ device and and programming language are you using, i.e., LabVIEW/CVI/.NET?   If you are new to DAQ, a great place to start are the example programs.  You can find the example programs with the Example Finder, located at Help >> Find Examples in both LabVIEW and CVI.  Once this opens, double click Hardware Input and Output >> DAQmx >> Analog Generation.  This will have many programs for generating waveforms.  I have also found a program online that might be worth looking at.  
    Continuous Multiple AO Waveforms
    Regards,
    Jim Schwartz

  • Using Start-Job to launch multiple SSH sessions and esxtop?

    Hello folks,
    I am trying to start an esxtop session on multiple esx servers at the same time.
    I started trying using Start-Job thinking it would help do it asynchronously.
    The script I have below works on one host so far, but need suggestions to repeat it for multiple hosts, thinking by looping through changing the $i each time?
    Checking if anyone would have comment?
    $i = 1
    $seconds = 5
    $iterations = 2
    $esxtopfile = "esxtop$i_$((Get-Date).ToString('MMddyyy-hhmm')).csv"
    $ComputerName = "z420esxi$i.domain.net"
    # Start an esxtop session using SSH.net and start an esxtop command - module already loaded.
    $sb = {New-SshSession -ComputerName $($args[0]) -KeyFile C:\esxi-key-openssh.key -Username root
           Invoke-SshCommand -ComputerName $($args[0]) -command "esxtop -d $($args[1]) -a -b -n $($args[2]) > /tmp/$($args[3])"     
    Start-Job  -ScriptBlock $sb -ArgumentList $ComputerName,$seconds,$iterations,$esxtopfile | Wait-Job | Receive-Job

A: Using Start-Job to launch multiple SSH sessions and esxtop?

You're starting for a job, waiting for that job to complete and then finally receiving that job
before allowing anything else to happen with your script.
In other words, if you had some code after the Start-Job line, it would not be executed until the job had completed and you had received the job, which partially negates the benefits of using a job to begin with (specially bearing in mind you don't have
a form).
The way to achieve what you're after is to start all jobs at the same time, one per ESX host, and then finally to wait for all jobs and collect all jobs at the end.
Here's a quick example that starts 5 jobs and wait for all of them to complete before receiving the results.
$jobs = @()
$jobs += 1..5 | ForEach-Object {Start-Job -ScriptBlock {Sleep $args[0]; "I just slept for $($args[0]) seconds"} -ArgumentList $_}
[void] (Wait-Job $jobs)
Receive-Job $jobs
Notice that each of the subsequent jobs will take longer and longer to run, with the first being the fastest and the last the slowest. Still, I'm waiting for *all* jobs to complete before performing the Receive-Jobs on all of them at the same time.

You're starting for a job, waiting for that job to complete and then finally receiving that job
before allowing anything else to happen with your script.
In other words, if you had some code after the Start-Job line, it would not be executed until the job had completed and you had received the job, which partially negates the benefits of using a job to begin with (specially bearing in mind you don't have
a form).
The way to achieve what you're after is to start all jobs at the same time, one per ESX host, and then finally to wait for all jobs and collect all jobs at the end.
Here's a quick example that starts 5 jobs and wait for all of them to complete before receiving the results.
$jobs = @()
$jobs += 1..5 | ForEach-Object {Start-Job -ScriptBlock {Sleep $args[0]; "I just slept for $($args[0]) seconds"} -ArgumentList $_}
[void] (Wait-Job $jobs)
Receive-Job $jobs
Notice that each of the subsequent jobs will take longer and longer to run, with the first being the fastest and the last the slowest. Still, I'm waiting for *all* jobs to complete before performing the Receive-Jobs on all of them at the same time.

  • Viewing multiple camera angles at the same time

    Hello -
    Basic question, that I'm sure has been answered many times before - so apologies for the repeat!
    I have been asked to take over editing some shows and gigs, which are filmed from up to four different camera angles. Each operator starts their camera, then runs it for the whole performance - so you end up with four long clips of video. The guy I am taking over from tells me that once you've got the four clips correctly aligned, it's actually a relatively simple job IF you can view all four clips at the same time. I basically need to be able to watch the whole show from start to finish, watching all four angles at the same time and doing a rough edit as I go, then go back and neaten things up.
    1. Will Final Cut Express do this?
    2. If the program can do it, am I right in thinking my iMac might be a bit underpowered?
    As you can probably tell, I'm not at all down with the lingo on video editing, so I hope my question makes sense!
    Thanks in advance,
    Joe

    Hi
    A VERY Good Answer from Tom.
    I do this in a slightly different way.
    Videos on one track each
    Re-sized to 25% as Tom describes
    Moved to sync.
    Then I don't use the blade tool - BUT adjust transparicy. So that needed angle get 100%
    rest goes to 0%
    Finalicing by re-sizing all back to 100%
    Done
    BUT if You can finance it - THIS is much easier to be done in FCP when getting the hang of
    how it works here. Much more like a Real-Time editing situation - Click on the view You like
    You don't even need to be very excat - Easily fixed with "roll tool" (I think it's named)
    If Time is of essence and mony not - FinalCut Pro about 10 times faser to me
    If other way around ==> FCE
    Yours Bengt W

  • How can I run 2 Dreamweaver windows at the same time?

    How can I run 2 Dreamweaver windows at the same time on my
    PC?
    basically I have 2 monitors and I want to edit CSS on one
    monitor and have the html page open on the other so I can quickly
    look from one to another with in a split second instead of taking
    that extra time to switch back and forth using the tabs at the top,
    I know I should probably invest into a mac so i can work out side
    of the Dreamweaver application window and I will in the future but
    is there any way i can do this on my windows XP pro PC?
    Thank you
    Maurice

    Open the CSS in DW, and use F10 to open the Code Inspector.
    Place the
    latter as needed.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "Random_Yggdrasil" <[email protected]> wrote
    in message
    news:gi2htb$j4j$[email protected]..
    > How can I run 2 Dreamweaver windows at the same time on
    my PC?
    > basically I have 2 monitors and I want to edit CSS on
    one monitor and have
    > the
    > html page open on the other so I can quickly look from
    one to another with
    > in a
    > split second instead of taking that extra time to switch
    back and forth
    > using
    > the tabs at the top, I know I should probably invest
    into a mac so i can
    > work
    > out side of the Dreamweaver application window and I
    will in the future
    > but is
    > there any way i can do this on my windows XP pro PC?
    >
    > Thank you
    > Maurice
    >
    >
    >

  • How do I view multiple inbox folders at the same time in Mail?

    I want to configure Mail to show me multiple inbox folders at the same time. I want to be able to split the screen and show in the top section unread messages, then messages I've marked with label A, then messsges I've marked with label B, then everything else in my inbox (like using the multiple inbox feature in Gmail). Is this possible?

    Just figured it out - I can select multiple messages as you suggested when I am not in full screen mode.
    So once I come out of full screen mode - then the multiple windows open.
    QED

  • Can I pair and use more than one set of bluetooth speakers at the same time on my ipod touch 4.0

    can I pair and use more than one set of bluetooth speakers at the same time on my ipod touch 4.0 or Iphone 4s or Ipad 2?

    You can only connect to one device at a time using Bluetooth, See article below for more information.
    http://support.apple.com/kb/ht1664
    While your iOS device can maintain multiple pairing records, it can only connect to one headset or hands-free device at a time. This prevents your iOS device from sending your data to the wrong Bluetooth accessory.

  • With my  Os X 10.7.5 , I updated outlook for mac, it took a while, kept wanting me to close microsoft database Daemon,finally managed to upgrade to outlook 14.3.2, after new start is EVERTYTHING in outlook Gone. At the same time updated our laptop, with n

    with my  Os X 10.7.5 , I updated outlook for mac, it took a while, kept wanting me to close microsoft database Daemon,finally managed to upgrade to outlook 14.3.2, after new start is EVERTYTHING in outlook Gone. At the same time updated our laptop, with n

    This forum is for troubleshooting Apple Software Update for Windows, a software package for Windows designed to update Apple products that run on Windows, and not related to Microsoft Office in any way. I suggest you post Office related questions on Microsoft's own forums for their Mac products.
    http://www.officeformac.com/productforums

  • Running Leopard and Tiger at the same time VMWare fusion/Parallels?

    Hello,
    I was wondering, is it possible to run Tiger and Leopard at the same time? Some older applications won't run properly in Leopard. The iMac came both with Tiger and Leopard (last November). It has been described elsewhere that one can install Tiger and Leopard on separate partitions and switch by rebooting. But it would be nice if one could run Tiger in Leopard like one can run Windows/Unix using VMWare Fusion or Parallels. Is that feasible?
    best wishes

    I agree with you that virtualizing Mac OS X would be great. I'm an Apple technician and it would really help with my work. But Apple's EULA does not permit the use of OS X in a VM. They changed OS X Server's EULA recently to permit it, but not the "client version".
    So your Mac can virtualize nearly any OS out there, but not OS X. And I believe (not sure) that a VM of OS X Server will only run on OS X Server.

  • Getting data from Multiple cDAQ racks at the same time.

    I need to combine an 8 port cDAQ rack and a 4 port cDAQ rack and was hoping someone can help.  I do not need the signals to be synced up exactly, but I can’t handle the 50ms delay that I have now.  The signals on the 2nd rack is more for customer reference and the 1st rack is doing all the real analyzing.
    I need to collect samples at 500hz or every 2ms and I collect 25 samples giving me a chunk of data every 50ms.  The DAQmx tasks seem to pull at the same time, therefore the cDAQ2 In chunk is always 1 scan behind causing a 50ms delay.
    Is there a better way to pull this data without having such a large delay?  I did not see anything in the examples that apply to my particular application and hardware.
    Thanks,
    Doug

    Each task will begin sampling data as soon as you start each task, so in order for each task to be synced, you want each start task to occur at as close to the same time as possible.  One way to try to do this is to put the start tasks together in a sequence structure.  This will ensure all your cofiguration steps for both tasks are complete before you start sampling.  How long are you runnig your application for?  If its not that long, I wouldn't worry about one of your chassis running faster than each other.  If you think that is becoming a problem, there are ways to diagnose that, but that would take a significant amount of effort.
    I have included a snippet of how you can try starting your tasks together
    Applications Engineer
    National Instruments
    Attachments:
    start tasks together.png ‏21 KB

  • Since upgrading to Mavericks, I can't run Mail and Safari at the same time.

    Since upgrading to Mavericks, I can't run Mail and Safari at the same time.
    Either Mail will crash or the iMac will run so slowly as to be unusable. With both running, the HDD spins constantly at a high rate of speed.

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Step 1
    Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left. If you don't see that menu, select
    View ▹ Show Log List
    from the menu bar.
    Enter the name of the crashed application or process in the Filter text field. Select the messages from the time of the last crash, if any. Copy them to the Clipboard by pressing the key combination command-C. Paste into a reply to this message (command-V).
    When posting a log extract, be selective. In most cases, a few dozen lines are more than enough.
    Please do not indiscriminately dump thousands of lines from the log into this discussion.
    Important: Some private information, such as your name, may appear in the log. Anonymize before posting.
    Step 2
    In the Console window, look under User Diagnostic Reports for crash reports related to the crashed process. The report name starts with the name of the process, and ends with ".crash". Select the most recent report and post the entire contents — again, the text, not a screenshot. In the interest of privacy, I suggest that, before posting, you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header of the report, if it’s present (it may not be.) Please don’t post shutdownStall, spin, or hang logs — they're very long and not helpful.

  • What do you think about running 2 security solutions at the same time? [malware event]

    Hi all
    Is there anyone here running 2 Security Solutions at the same time?
    From what I know, few of my lecturers are running AVG and Avira, or Avira and MSE. (All free)
    According to their theory, school-licensed Symantec Endpoint Protection slows down the system too much till a point that it is slow or unable to detect the threats. 1 antivirus is not good enough, 2 antivirus would be able to detect 100% of malware.
    For my school labs computer, they are running both Symantec Endpoint Protection and Microsoft Security Essential at the same time.
    Does 2 security solutions or more helps your computer to be risk-free?
    Cheers 
    Peter
    (Current: W520 4284-A99) (Refunded: W510 4876-A11)
    =============================================
    Does someone’s post help you? Give them kudos as a reward, as they will do better to improve 
    Mark it as solved if the solution works for you, so it could be reference for others in the future 
    Dolby Home Theater v4 (ThinkMix V2)!
    http://forums.lenovo.com/t5/W-Series-ThinkPad-Lapt​ops/W520-Sound-Enhancement-Thread/m-p/451401#M155... 
    Solved!
    Go to Solution.

    Hello,
    Generally speaking, you should not run two security programs together at the same time which run in "real-time," e.g., they are actively monitoring the system.  The reason for this is that the various real-time components (on-access file system scanner, network traffic filter, and so forth) may interfere with each others operations as they both attempt to access the same bits at the same time.  This can lead to all sorts of strange system behavior, such as slowdowns, program crashes, failed downloads and lock-ups.
    If you are going to do this, make sure you disable the realtime scanning components of one program, or use one program to actively monitor the system and the other to periodically perform an scheduled or manual scans on demand.
    Regards,
    Aryeh Goretsky
    I am a volunteer and neither a Lenovo nor a Microsoft employee. • Dexter is a good dog • Dexter je dobrý pes
    S230u (3347-4HU) • X220 (4286-CTO) • W510 (4318-CTO) • W530 (2441-4R3) • X100e (3508-CTO) • X120e (0596-CTO) • T61p (6459-CTO) • T43p (2678-H7U) • T42 (2378-R4U) • T23 (2648-LU7)
      Deutsche Community   Comunidad en Español Русскоязычное Сообщество

  • Why can't I run Safari and Skype at the same time without making my computer freeze up?

    I can't believe I can't run Safari and Skype at the same time without my computer freezing up, it's a MacBook Pro with Mac OS 10.6.8 and it has an Intel Core 2 Duo CPU with 2.2 Ghz and 2 Gb of RAM. Is this a hardware problem or a software problem?

    I haven't gone to the trouble of actually testing to see which uses more CPU power, but Firefox has been faster than Safari on every Mac I've ever owned.
    To see CPU usage by process, open the terminal (in Utilities) and enter 'top' at the command line. You might have to expand the window as processes don't appear in any logical order.
    It could also be hardware-related: I have late 2009 mini with similar specs and it pinwheels easily.

  • We have a PCI-6110S to run our VIs. But, we are planing to buy another card (PCI-6024E​) to run real time PID vi. So, if they are installed at the same computer, would it be a problem for LabVIEW to run both of them at the same time.

    We have PCI-6110 S series installed in our computer. We are planing to purchase PCI-6024 E series card. They will be both installed at the same computer.
    1) I am wondering if we run both of them at the same time, would we have any problem?
    2) To run PID real time, can any E series of PCI card be used?
    Thanks...

    Hello Baho,
    1) Using Traditional NI-DAQ, there could be problems with the fact that the NI-DAQ driver is not multi-threaded; meaning that while waiting for one operation to complete, the driver could cause another operation to time out. On the other hand, DAQmx is multi-threaded, and would eliminate this problem. At the time of this writing though, DAQmx does not yet support simultaneous-sampling boards like the PCI-6110S. A good solution then would be to use Traditional DAQ for the 6110S and DAQmx for the E-series board, and they would by default run in separate threads.
    2) No, using a PCI E-Series board, the LabVIEW VI would have to run in a Windows OS and would not be Real Time or run deterministically. You can run the PID program in Windows, but the
    results could be inconsistent. The advantage of a Real Time is that the OS is deterministic or that the OS allows you to tightly control or determine the maximum time any function takes to operate. This kind of control of the maximum operation time is not possible with non-Real Time OSs such as Windows.
    If you would like to get set up with a Real Time System, I suggest you contact your Technical Sales Representative.
    Regards,
    Chad Evans
    National Instruments

  • Maybe you are looking for