Skip to content

Commit f29c76d

Browse files
Add Get-Runspace compatibility function for PS v3/v4 (#9731)
1 parent 71373f6 commit f29c76d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

opt/Get-Runspace.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
if (-not $ExecutionContext.SessionState.InvokeCommand.GetCommand('Get-Runspace','Function,Cmdlet')) {
2+
function Get-Runspace {
3+
try {
4+
$runspaces = [Dataplat.Dbatools.Runspace.RunspaceHost]::Runspaces.Values
5+
foreach ($rs in $runspaces) {
6+
$availability = switch ($rs.State.ToString()) {
7+
'Running' { 'Available' }
8+
default { 'NotAvailable' }
9+
}
10+
[PSCustomObject]@{
11+
Id = $rs.RunspaceGuid
12+
Name = $rs.Name
13+
Type = $rs.GetType().Name
14+
State = $rs.State
15+
Availability = $availability
16+
InstanceId = $rs.RunspaceGuid
17+
}
18+
}
19+
} catch {
20+
Write-Warning "Unable to enumerate dbatools-managed runspaces: $_"
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)