Skip to content

Commit

Permalink
ShouldProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Sep 14, 2017
1 parent 24c2a66 commit 5d2629f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = ".\AzureRM.Compute.Experiments.psm1"

# Version number of this module.
ModuleVersion = '1.0.4'
ModuleVersion = '1.0.5'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
14 changes: 8 additions & 6 deletions experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.ExternalHelp AzureRM.Compute.Experiments-help.xml
#>
function New-AzVm {
[CmdletBinding()]
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory=$true, Position=0)][string] $Name = "VM",
[Parameter()][PSCredential] $Credential,
Expand Down Expand Up @@ -42,12 +42,14 @@ function New-AzVm {
$locationi.Value = $Location;
}

$resourceGroup = $rgi.GetOrCreate($Name + "ResourceGroup", $locationi.Value, $null);
$vmResponse = $vmi.Create($Name, $locationi.Value, $resourceGroup.ResourceGroupName);
if ($PSCmdlet.ShouldProcess($Name, "Creating a virtual machine")) {
$resourceGroup = $rgi.GetOrCreate($Name + "ResourceGroup", $locationi.Value, $null);
$vmResponse = $vmi.Create($Name, $locationi.Value, $resourceGroup.ResourceGroupName);

New-PsObject @{
ResourceId = $resourceGroup.ResourceId;
Response = $vmResponse;
New-PsObject @{
ResourceId = $resourceGroup.ResourceId;
Response = $vmResponse;
}
}
}
}
Expand Down

0 comments on commit 5d2629f

Please sign in to comment.