Skip to content

Commit 1542122

Browse files
author
Staffan Gustafsson
committed
Fixing nullreference issue with -NoProgress
1 parent e433a6c commit 1542122

File tree

4 files changed

+73
-23
lines changed

4 files changed

+73
-23
lines changed

module/PSParallel.psd1

146 Bytes
Binary file not shown.

module/en-US/PSParallel.dll-Help.xml

+50-6
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,48 @@ at contains the objects, or type a command or expression that gets the objects.<
8888
</maml:description>
8989
<command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
9090
</command:parameter>
91-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
91+
</command:syntaxItem>
92+
<command:syntaxItem>
93+
<maml:name>Invoke-Parallel</maml:name>
94+
<command:parameter required="true" pipelineinput="false" globbing="false" position="named">
95+
<maml:name>ScriptBlock</maml:name>
96+
<maml:description>
97+
<maml:para>Specifies the operation that is performed on each input object. Enter a script block that describes the operation.</maml:para>
98+
</maml:description>
99+
<command:parameterValue required="true">ScriptBlock</command:parameterValue>
100+
</command:parameter>
101+
<command:parameter required="false" pipelineinput="false" globbing="false" position="named">
102+
<maml:name>ThrottleLimit</maml:name>
103+
<maml:description>
104+
<maml:para>Specifies the maximum number of concurrent connections that can be established to run this command. If you omit this
105+
parameter or enter a value of 0, the default value, 16, is used.</maml:para>
106+
</maml:description>
107+
<command:parameterValue required="false">Int32</command:parameterValue>
108+
</command:parameter>
109+
<command:parameter required="true" pipelineinput="True (ByValue)" globbing="false" position="named">
110+
<maml:name>InputObject</maml:name>
111+
<maml:description>
112+
<maml:para>Specifies the input objects. Invoke-Parallel runs the script block on each input object in parallel. Enter a variable th
113+
at contains the objects, or type a command or expression that gets the objects.</maml:para>
114+
</maml:description>
115+
<command:parameterValue required="true">PSObject</command:parameterValue>
116+
</command:parameter>
117+
<command:parameter required="false" pipelineinput="false" globbing="false" position="named">
92118
<maml:name>NoProgress</maml:name>
93119
<maml:description>
94120
<maml:para>Will not show progress from Invoke-Progress. Progress from the scriptblock will still be displayed.</maml:para>
95121
</maml:description>
96-
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
97-
<dev:defaultValue/>
122+
<command:parameterValue required="false">SwitchParameter</command:parameterValue>
123+
</command:parameter>
124+
<command:parameter required="true" pipelineinput="false" globbing="false" position="named">
125+
<maml:name>InitialSessionState</maml:name>
126+
<maml:description>
127+
<maml:para>The session state used by the runspaces when invoking ScriptBlock. This provides the functions, variables, drives, etc
128+
available to the ScriptBlock.
129+
By default, InitialSessionState.Create2() is used and the functions and variables from the current scope is then
130+
imported.</maml:para>
131+
</maml:description>
132+
<command:parameterValue required="true">InitialSessionState</command:parameterValue>
98133
</command:parameter>
99134
</command:syntaxItem>
100135
</command:syntax>
@@ -204,6 +239,14 @@ imported.</maml:para>
204239
</dev:type>
205240
<dev:defaultValue/>
206241
</command:parameter>
242+
<command:parameter required="false" globbing="false" pipelineInput="false" position="named">
243+
<maml:name>Parameter8</maml:name>
244+
<maml:description>
245+
<maml:para/>
246+
</maml:description>
247+
<command:parameterValue required="false"/>
248+
<dev:defaultValue/>
249+
</command:parameter>
207250
</command:parameters>
208251
<command:inputTypes>
209252
<!--Inputs-->
@@ -233,10 +276,11 @@ imported.</maml:para>
233276
<maml:introduction>
234277
<maml:para>PS C:\&gt;</maml:para>
235278
</maml:introduction>
236-
<dev:code>(1..255).ForEach{&quot;192.168.0.$_&quot;} | Invoke-Parallel {$ip = $_; $res = ping.exe -4 -w 20 $_; [PSCustomObject] @{IP=$ip;Res=$res}} -ThrottleLimit 64</dev:code>
279+
<dev:code>(1..255).ForEach{&quot;192.168.0.$_&quot;} |
280+
Invoke-Parallel {$ip = [IPAddress]$_; $res = ping.exe -n 1 -4 -w 20 -a $_; [PSCustomObject] @{IP=$ip;Res=$res}} -ThrottleLimit 64</dev:code>
237281
<dev:remarks>
238-
<maml:para>This example pings all iP v4 addresses on a subnet, specifying Throttlelimit to 64, i.e. running up to 64 runspaces in p
239-
arallel.</maml:para>
282+
<maml:para>This example pings all iP v4 addresses on a subnet, specifying Throttlelimit to 64, i.e. running up to 64 runspaces
283+
in parallel.</maml:para>
240284
</dev:remarks>
241285
</command:example>
242286
</command:examples>

scripts/Publish-ToGallery.ps1

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
$manPath = Get-ChildItem -recurse $PSScriptRoot/../module -include *.psd1 | select -first 1
2+
$man = Test-ModuleManifest $manPath
3+
4+
$name = $man.Name
5+
[string]$version = $man.Version
6+
17
$p = @{
2-
Name = "PSParallel"
8+
Name = $name
39
NuGetApiKey = $NuGetApiKey
10+
RequiredVersion = $version
411
}
512

613
Publish-Module @p

src/PSParallel/InvokeParallelCommand.cs

+15-16
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,38 @@
1212
namespace PSParallel
1313
{
1414
[Alias("ipa")]
15-
[Cmdlet("Invoke", "Parallel", DefaultParameterSetName = "SessionStateParams")]
15+
[Cmdlet("Invoke", "Parallel", DefaultParameterSetName = "Progress")]
1616
public sealed class InvokeParallelCommand : PSCmdlet, IDisposable
1717
{
1818
[Parameter(Mandatory = true, Position = 0)]
1919
public ScriptBlock ScriptBlock { get; set; }
2020

21-
[Alias("ppi")]
22-
[Parameter(ParameterSetName = "InitialSessionState")]
23-
[Parameter(ParameterSetName = "SessionStateParams")]
24-
[Parameter(ParameterSetName = "")]
21+
[Parameter(ParameterSetName = "Progress")]
22+
[Alias("ppi")]
2523
public int ParentProgressId { get; set; } = -1;
2624

27-
[Alias("pi")]
28-
[Parameter(ParameterSetName = "InitialSessionState")]
29-
[Parameter(ParameterSetName = "SessionStateParams")]
25+
[Parameter(ParameterSetName = "Progress")]
26+
[Alias("pi")]
3027
public int ProgressId { get; set; } = 1000;
3128

32-
[Alias("pa")]
33-
[Parameter(ParameterSetName = "InitialSessionState")]
34-
[Parameter(ParameterSetName = "SessionStateParams")]
29+
[Parameter(ParameterSetName = "Progress")]
30+
[Alias("pa")]
3531
[ValidateNotNullOrEmpty]
3632
public string ProgressActivity { get; set; } = "Invoke-Parallel";
3733

3834
[Parameter]
3935
[ValidateRange(1,128)]
4036
public int ThrottleLimit { get; set; } = 32;
4137

42-
[Parameter(ParameterSetName = "InitialSessionState", Mandatory = true)]
38+
[Parameter]
4339
[AllowNull]
4440
[Alias("iss")]
4541
public InitialSessionState InitialSessionState { get; set; }
4642

4743
[Parameter(ValueFromPipeline = true, Mandatory = true)]
4844
public PSObject InputObject { get; set; }
4945

50-
[Parameter]
46+
[Parameter(ParameterSetName = "NoProgress")]
5147
public SwitchParameter NoProgress { get; set; }
5248

5349
private readonly CancellationTokenSource m_cancelationTokenSource = new CancellationTokenSource();
@@ -264,9 +260,12 @@ private void WriteOutputs()
264260
p.ParentActivityId = m_progressManager.ActivityId;
265261
}
266262
WriteProgress(p);
267-
}
268-
m_progressManager.UpdateCurrentProgressRecord(m_powershellPool.ProcessedCount + m_powershellPool.GetPartiallyProcessedCount());
269-
WriteProgress(m_progressManager.ProgressRecord);
263+
}
264+
if(!NoProgress)
265+
{
266+
m_progressManager.UpdateCurrentProgressRecord(m_powershellPool.ProcessedCount + m_powershellPool.GetPartiallyProcessedCount());
267+
WriteProgress(m_progressManager.ProgressRecord);
268+
}
270269
}
271270
}
272271

0 commit comments

Comments
 (0)