Skip to content

Commit 55c6002

Browse files
author
Maddie Clayton
authored
Merge pull request #7242 from Azure/maddieclayton-patch-1
Update piping-in-powershell.md
2 parents f889a07 + fcdcb5d commit 55c6002

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

documentation/development-docs/piping-in-powershell.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,30 +192,27 @@ For example, you have a `Remove-AzureRmFoo` cmdlet with the following parameters
192192

193193
```cs
194194
[Parameter(ParameterSetName = "ByPropertyName", ValueFromPipelineByPropertyName = true)]
195-
public string Name { get; set; }
196-
197-
[Parameter(ParameterSetName = "ByPropertyName", ValueFromPipelineByPropertyName = true)]
198-
public string ResourceGroupName { get; set; }
195+
public string ResourceId { get; set; }
199196
```
200197

201198
If there is a corresponding `Get-AzureRmFoo` cmdlet that returns a `PSFoo` object (that has properties `Name` and `ResourceGroupName`), the following scenario is enabled:
202199

203200
```powershell
204201
# --- Piping scenario ---
205202
# Remove an individual PSFoo object
206-
Get-AzureRmFoo -Name "FooName" -ResourceGroupName "RG" | Remove-AzureRmFoo
203+
Get-AzureRmResource -ResourceId <resourceId> | Remove-AzureRmFoo
207204
208205
# Remove all PSFoo objects
209-
Get-AzureRmFoo | Remove-AzureRmFoo
206+
Get-AzureRmResource -ResourceType Foo | Remove-AzureRmFoo
210207
211208
212209
# --- Non-piping scenario ---
213210
# Remove an individual PSFoo object
214-
$foo = Get-AzureRmFoo -Name "FooName" -ResourceGroupName "RG"
215-
Remove-AzureRmFoo -Name $foo.Name -ResourceGroupName $foo.ResourceGroupName
211+
$foo = Get-AzureRmResource -ResourceId <resourceId>
212+
Remove-AzureRmFoo -ResourceId <resourceId>
216213
217214
# Remove all PSFoo objects
218-
Get-AzureRmFoo | ForEach-Object { Remove-AzureRmFoo -Name $_.Name -ResourceGroupName $_.ResourceGroupName }
215+
Get-AzureRmFoo | ForEach-Object { Remove-AzureRmFoo -ResourceId <resourceId> }
219216
```
220217

221218
The `PSFoo` object(s) that is returned by the `Get-AzureRmFoo` call will be piped to the `Remove-AzureRmFoo` cmdlet, and because that cmdlet has parameters that accept their value from the pipeline by property name, PowerShell will check each of these parameters and see if it can find a corresponding property in the `PSFoo` object that it shares a name with, and bind the value.

tools/StaticAnalysis/Program.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ----------------------------------------------------------------------------------
1+
// ----------------------------------------------------------------------------------
22
//
33
// Copyright Microsoft Corporation
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,7 +52,7 @@ public static void Main(string[] args)
5252
if (args.Any(a => a == "--package-directory" || a == "-p"))
5353
{
5454
int idx = Array.FindIndex(args, a => a == "--package-directory" || a == "-p");
55-
if (idx == args.Length)
55+
if (idx + 1 == args.Length)
5656
{
5757
throw new ArgumentException("No value provided for the --package-directory parameter.");
5858
}
@@ -81,7 +81,7 @@ public static void Main(string[] args)
8181
if (args.Any(a => a == "--reports-directory" || a == "-r"))
8282
{
8383
int idx = Array.FindIndex(args, a => a == "--reports-directory" || a == "-r");
84-
if (idx == args.Length)
84+
if (idx + 1 == args.Length)
8585
{
8686
throw new ArgumentException("No value provided for the --reports-directory parameter.");
8787
}
@@ -98,12 +98,20 @@ public static void Main(string[] args)
9898
if (args.Any(a => a == "--modules-to-analyze" || a == "-m"))
9999
{
100100
int idx = Array.FindIndex(args, a => a == "--modules-to-analyze" || a == "-m");
101-
if (idx == args.Length)
101+
if (idx + 1 == args.Length)
102+
{
103+
Console.WriteLine("No value provided for the --modules-to-analyze parameter.");
104+
}
105+
else
102106
{
103-
throw new ArgumentException("No value provided for the --modules-to-analyze parameter.");
107+
modulesToAnalyze = args[idx + 1].Split(';').ToList();
104108
}
109+
}
105110

106-
modulesToAnalyze = args[idx + 1].Split(';').ToList();
111+
if (!modulesToAnalyze.Any())
112+
{
113+
Console.WriteLine("No modules were found to analyze -- skipping Static Analysis check.");
114+
return;
107115
}
108116

109117
bool useNetcore = args.Any(a => a == "--use-netcore" || a == "-u");

0 commit comments

Comments
 (0)