티스토리 뷰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | $ScriptBlock = { param( [Parameter(Position=0, Mandatory=$false)][int]$threadNum=$(throw "threadNum param is not null"), [Parameter(Position=0, Mandatory=$false)][string]$targetServer=$(throw "targetServer param is not null"), [Parameter(Position=0, Mandatory=$false)][string]$command=$(throw "command param is not null"), [Parameter(Position=0, Mandatory=$false)][string]$password ) try { $pw = convertto-securestring -AsPlainText -Force -String "$password" $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "$targetServer\Administrator",$pw $session = new-pssession -computername "$targetServer" -credential $cred $cmd = [scriptblock]::Create($command) $CmdResult = Invoke-Command -Session $session -ScriptBlock $cmd } catch [Exception] { $CmdResult = $_.Exception.Message } $RunResult = New-Object PSObject -Property @{ Num = $threadNum Server = $targetServer Result = $CmdResult } Get-PSSession|Remove-PSSession Return $RunResult } function TheradRemotesCmd{ param( [Parameter(Position=0, Mandatory=$false)][string]$serverFile=$(throw "serverFile param is not null"), [Parameter(Position=0, Mandatory=$false)][string]$command=$(throw "command param is not null"), [Parameter(Position=0, Mandatory=$false)][string]$password ) $Throttle = 10 #threads $RunspacePool = [RunspaceFactory]::CreateRunspacePool(1, $Throttle) $RunspacePool.Open() $Jobs = @() $threadNum = 1 foreach ($targetServer in get-content $serverFile){ $Job = [powershell]::Create().AddScript($ScriptBlock).AddParameter("threadNum", $threadNum).AddParameter("targetServer", $targetServer).AddParameter("command", $command).AddParameter("password", $password) $Job.RunspacePool = $RunspacePool $Jobs += New-Object PSObject -Property @{ Server = $targetServer Pipe = $Job Result = $Job.BeginInvoke() } $threadNum += 1 } Write-Host "Waiting.." -NoNewline Do { Write-Host "." -NoNewline Start-Sleep -Seconds 1 } While ( $Jobs.Result.IsCompleted -contains $false) Write-Host "All jobs completed!" $Results = @() ForEach ($Job in $Jobs) { $Results += $Job.Pipe.EndInvoke($Job.Result) } $Results | Out-GridView } TheradRemotesCmd -serverFile server_list.txt -command "hostname" | cs |
'운영체제' 카테고리의 다른 글
Linux 원격 tar 백업/복원 (0) | 2016.12.26 |
---|---|
Linux 리얼 서버로 VM 이미지 만들기 (0) | 2016.12.22 |
윈도우 Scheduled Tasks 등록 명령어 (0) | 2016.11.23 |
Linux sar로 시스템 모니터링 (0) | 2016.08.19 |
Linux 자원 모니터링 도구 (0) | 2016.08.17 |
댓글
warpmemory
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
페이지
TAG
- monitoring
- Python
- 번역
- mysql
- RESTful
- limits
- code
- 명령어
- Linux
- MariaDB
- 외부링크
- File
- engineering
- Web
- Windows
- apache
- Module
- 코드
- deview
- Ansible
- 예제
- configuration
- error
- client
- check
- example
- PowerShell
- 이슈처리
- httpd
- command
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
글 보관함