Need a script to use a threading.

Welcome Forums General PowerShell Q&A Need a script to use a threading.

This topic contains 3 replies, has 4 voices, and was last updated by

4 years, 8 months ago.

  • Author
  • #16314

    Points: 0
    Rank: Member

    Hi All,

    I want to run a T-SQL batch statement (select statement) in 1000+ servers. But if i run the script using regular powershell, it will take a long time as it will refer the serverlist .txt file to read each server entry, then it will call a powershell script where each server will be passed as a loop then the results will be copied to an output file.

    Instead of that, I think to use PS thread where a bunch of 10 servers will be taken a at a time, so that the select statement which I want to run against the servers would be completed sooner.

    Reply me with your inputs.


  • #16316

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    PowerShell is a single threaded application. Consider using background jobs.

  • #16318

    Points: 0
    Rank: Member

    You could compress your script into a single T-SQL statement instead of running 1000+ SELECT queries

    $servers = Get-Content servers.txt
    $servers = $servers -join "','"
    $query = "SELECT * FROM table WHERE servername IN ('$servers')


  • #16353

    Points: 0
    Rank: Member

    Have you looked into background runspaces?

    There's a great into to the concept at
    I've also got background runspaces heavily used in – feel free to look at the code and use the relevant parts as needed to get up to speed on how runspaces work.

The topic ‘Need a script to use a threading.’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort