-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunSpace Mount
More file actions
44 lines (31 loc) · 1.17 KB
/
RunSpace Mount
File metadata and controls
44 lines (31 loc) · 1.17 KB
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
$Worker = {
param($Name,$webapp,$NormalizedDataSource)
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Write-Host "Mounting $Name.name to $name.webapp"
Mount-SPContentDatabase -WebApplication $name.webapp -Name $Name.name -DatabaseServer $name.NormalizedDataSource
Write-Host "$Name.name has been mounted to $name.webapp"
Start-Sleep 50
}
$MaxRunspaces = 5
$RunspacePool = [runspacefactory]::CreateRunspacePool(1, $MaxRunspaces)
$RunspacePool.Open()
$Jobs = New-Object System.Collections.ArrayList
$databases = Import-Csv "contentdbs.csv"
foreach ($item in $databases) {
Write-Host "Creating runspace for $Item"
$PowerShell = [powershell]::Create()
$PowerShell.RunspacePool = $RunspacePool
$PowerShell.AddScript($Worker).AddArgument($item) | Out-Null
$JobObj = New-Object -TypeName PSObject -Property @{
Runspace = $PowerShell.BeginInvoke()
PowerShell = $PowerShell
}
$Jobs.Add($JobObj) | Out-Null
}
while ($Jobs.Runspace.IsCompleted -contains $false) {
Write-Host (Get-date).Tostring() "Still running..."
Start-Sleep 1
}
Start-Transcript -Path Computer.log
Write-Host "everything will end up in Computer.log"
Stop-Transcript