-
Notifications
You must be signed in to change notification settings - Fork 4.1k
latest powershell changes for azurestackhci #29211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
486e37c
656e308
9ab3112
dd0a2ee
19a55b9
fb1b095
c0af3cb
dba104b
45c864f
227d6f1
32873a2
ba1697f
fcd1445
0fe00cc
114ee5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,9 +102,10 @@ function New-AzStackHCIVMImage{ | |
|
|
||
| [Parameter(ParameterSetName='GalleryImage', Mandatory)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Body')] | ||
| [System.String] | ||
| # Local path of image that the image should be created from. | ||
| # This parameter is required for non marketplace images. | ||
| [System.Security.SecureString] | ||
| # Local path of image that the image should be created from (as SecureString). | ||
| # This parameter is required for non marketplace images. | ||
| # Use: ConvertTo-SecureString -String "path\to\image.vhdx" -AsPlainText -Force | ||
| ${ImagePath}, | ||
|
|
||
shraddhasun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [Parameter(ParameterSetName='GalleryImage', Mandatory)] | ||
|
|
@@ -333,12 +334,14 @@ function New-AzStackHCIVMImage{ | |
| Start-Sleep -Seconds 5 | ||
| if ($image.ProvisioningStatus -eq "Failed") { | ||
| Break | ||
| } | ||
| } | ||
| if (($PercentCompleted -ne 100) -and ($image.ProvisioningStatus -ne "Failed")) { | ||
| Start-Sleep -Seconds 5 | ||
| } | ||
|
Comment on lines
333
to
+339
|
||
| } | ||
| if ($image.ProvisioningStatus -eq "Failed"){ | ||
| Write-Error $image.StatusErrorMessage -ErrorAction Stop | ||
| } | ||
|
|
||
| } catch { | ||
| $e = $_ | ||
| if ($e.FullyQualifiedErrorId -match "MissingAzureKubernetesMapping" ){ | ||
|
|
@@ -416,6 +419,9 @@ function New-AzStackHCIVMImage{ | |
| if ($PSCmdlet.ParameterSetName -eq "GalleryImage") | ||
| { | ||
| try{ | ||
| $plainImagePath = [System.Net.NetworkCredential]::new('', $ImagePath).Password | ||
| $null = $PSBoundParameters.Remove("ImagePath") | ||
| $PSBoundParameters.Add("ImagePath", $plainImagePath) | ||
| Az.StackHCIVM.internal\New-AzStackHCIVMGalleryImage -ErrorAction Stop @PSBoundParameters | ||
| } catch { | ||
| $e = $_ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -227,8 +227,8 @@ function New-AzStackHCIVMVirtualMachine { | |
|
|
||
| [Parameter()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Body')] | ||
| [System.String] | ||
| # AdminPassword - admin password | ||
| [System.Security.SecureString] | ||
| # AdminPassword - admin password (as SecureString) | ||
shraddhasun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ${AdminPassword}, | ||
|
Comment on lines
+230
to
232
|
||
|
|
||
shraddhasun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [Parameter()] | ||
|
|
@@ -657,6 +657,7 @@ function New-AzStackHCIVMVirtualMachine { | |
| if ($ComputerName){ | ||
| $PSBoundParameters.Add('ComputerName', $ComputerName) | ||
| } | ||
| # Handle credentials - either from Credential parameter or direct AdminUsername/AdminPassword | ||
| if ($AdminUsername){ | ||
| $PSBoundParameters.Add('AdminUsername', $AdminUsername) | ||
| } | ||
|
|
@@ -675,7 +676,7 @@ function New-AzStackHCIVMVirtualMachine { | |
| if ($EnableTpm.IsPresent){ | ||
| $PSBoundParameters.Add('EnableTpm', $EnableTpm) | ||
| } | ||
| if($SecureBootEnabled.IsPresent){ | ||
| if ($SecureBootEnabled.IsPresent){ | ||
| $PSBoundParameters.Add('SecureBootEnabled', $SecureBootEnabled) | ||
| } | ||
| $null = $PSBoundParameters.Remove("Name") | ||
|
|
@@ -688,7 +689,6 @@ function New-AzStackHCIVMVirtualMachine { | |
| $null = $PSBoundParameters.Remove("Location") | ||
| $null = $PSBoundParameters.Remove("OSType") | ||
| $null = $PSBoundParameters.Remove("IdentityType") | ||
|
|
||
| try{ | ||
| Az.StackHCIVM.internal\New-AzStackHCIVMVirtualMachine -ErrorAction Stop @PSBoundParameters | ||
| } catch { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
|
|
||
| # ---------------------------------------------------------------------------------- | ||
| # | ||
| # Copyright Microsoft Corporation | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ---------------------------------------------------------------------------------- | ||
|
|
||
| <# | ||
| .Synopsis | ||
| The operation to save a virtual machine instance. | ||
| .Description | ||
| The operation to save a virtual machine instance. | ||
|
|
||
| .Outputs | ||
| Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Models.IVirtualMachineInstance | ||
| .Notes | ||
| COMPLEX PARAMETER PROPERTIES | ||
|
|
||
|
|
||
| .Link | ||
| https://learn.microsoft.com/powershell/module/az.stackhcivm/Save-AzStackHCIVMVirtualMachine | ||
shraddhasun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #> | ||
| function Save-AzStackHCIVMVirtualMachine { | ||
| [OutputType([Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Models.IVirtualMachineInstance])] | ||
| [CmdletBinding( PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] | ||
shraddhasun marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+31
to
+33
|
||
| param( | ||
shraddhasun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [Parameter(ParameterSetName='ByName', Mandatory)] | ||
| [Alias('VirtualMachineName')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Path')] | ||
| [System.String] | ||
| # Name of the virtual machine | ||
| ${Name}, | ||
|
|
||
| [Parameter(ParameterSetName='ByName', Mandatory)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Path')] | ||
| [System.String] | ||
| # The name of the resource group. | ||
| # The name is case insensitive. | ||
| ${ResourceGroupName}, | ||
|
|
||
| [Parameter(ParameterSetName='ByName', Mandatory)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Path')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')] | ||
| [System.String] | ||
| # The ID of the target subscription. | ||
| ${SubscriptionId}, | ||
|
|
||
| [Parameter(ParameterSetName='ByResourceId', Mandatory)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Path')] | ||
| [System.String] | ||
| # The ARM Resource ID of the virtual machine. | ||
| ${ResourceId}, | ||
|
|
||
| [Parameter()] | ||
| [Alias('AzureRMContext', 'AzureCredential')] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Azure')] | ||
| [System.Management.Automation.PSObject] | ||
| # The credentials, account, tenant, and subscription used for communication with Azure. | ||
| ${DefaultProfile}, | ||
|
|
||
| [Parameter()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| # Run the command as a job | ||
| ${AsJob}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| # Wait for .NET debugger to attach | ||
| ${Break}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Runtime.SendAsyncStep[]] | ||
| # SendAsync Pipeline Steps to be appended to the front of the pipeline | ||
| ${HttpPipelineAppend}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Runtime.SendAsyncStep[]] | ||
| # SendAsync Pipeline Steps to be prepended to the front of the pipeline | ||
| ${HttpPipelinePrepend}, | ||
|
|
||
| [Parameter()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| # Run the command asynchronously | ||
| ${NoWait}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Uri] | ||
| # The URI for the proxy server to use | ||
| ${Proxy}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Management.Automation.PSCredential] | ||
| # Credentials for a proxy server to use for the remote call | ||
| ${ProxyCredential}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| # Use the default credentials for the proxy | ||
| ${ProxyUseDefaultCredentials} | ||
|
|
||
| ) | ||
| if (($resourceId -match $vmRegex) -or ($name -and $resourceGroupName -and $subscriptionId)){ | ||
| if ($resourceId -match $vmRegex){ | ||
| $subscriptionId = $($Matches['subscriptionId']) | ||
| $resourceGroupName = $($Matches['resourceGroupName']) | ||
| $name = $($Matches['machineName']) | ||
| } | ||
| $resourceUri = "/subscriptions/" + $subscriptionId + "/resourceGroups/" + $resourceGroupName + "/providers/Microsoft.HybridCompute/machines/" + $name | ||
| $PSBoundParameters.Add("ResourceUri", $resourceUri) | ||
| $null = $PSBoundParameters.Remove("SubscriptionId") | ||
| $null = $PSBoundParameters.Remove("ResourceGroupName") | ||
| $null = $PSBoundParameters.Remove("ResourceId") | ||
| $null = $PSBoundParameters.Remove("Name") | ||
|
|
||
| if ($PSCmdlet.ShouldProcess($resourceUri, "Save virtual machine instance")) { | ||
| try{ | ||
| Az.StackHCIVM.internal\Save-AzStackHCIVMVirtualMachine -ErrorAction Stop @PSBoundParameters | ||
| } catch { | ||
| $e = $_ | ||
| if ($e.FullyQualifiedErrorId -match "MissingAzureKubernetesMapping" ){ | ||
| Write-Error "An older version of the Arc VM cluster extension is installed on your cluster. Please downgrade the Az.StackHCIVm version to 1.0.1 to proceed." -ErrorAction Stop | ||
| } else { | ||
|
Comment on lines
+141
to
+143
|
||
| Write-Error -ErrorRecord $e -ErrorAction Stop | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } else { | ||
| Write-Error "One or more input parameters are invalid. Resource ID is: $resourceId, name is $name, resource group name is $resourceGroupName, subscription id is $subscriptionId" -ErrorAction Stop | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
|
|
||
| # ---------------------------------------------------------------------------------- | ||
| # | ||
| # Copyright Microsoft Corporation | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ---------------------------------------------------------------------------------- | ||
|
|
||
| <# | ||
| .Synopsis | ||
| The operation to Suspend a virtual machine instance. | ||
| .Description | ||
| The operation to Suspend a virtual machine instance. | ||
|
|
||
| .Outputs | ||
| Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Models.IVirtualMachineInstance | ||
| .Notes | ||
| COMPLEX PARAMETER PROPERTIES | ||
|
|
||
|
|
||
| .Link | ||
| https://learn.microsoft.com/powershell/module/az.stackhcivm/Suspend-AzStackHCIVMVirtualMachine | ||
shraddhasun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #> | ||
| function Suspend-AzStackHCIVMVirtualMachine { | ||
| [OutputType([Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Models.IVirtualMachineInstance])] | ||
| [CmdletBinding( PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] | ||
shraddhasun marked this conversation as resolved.
Show resolved
Hide resolved
shraddhasun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| param( | ||
shraddhasun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [Parameter(ParameterSetName='ByName', Mandatory)] | ||
| [Alias('VirtualMachineName')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Path')] | ||
| [System.String] | ||
| # Name of the virtual machine | ||
| ${Name}, | ||
|
|
||
| [Parameter(ParameterSetName='ByName', Mandatory)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Path')] | ||
| [System.String] | ||
| # The name of the resource group. | ||
| # The name is case insensitive. | ||
| ${ResourceGroupName}, | ||
|
|
||
| [Parameter(ParameterSetName='ByName', Mandatory)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Path')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')] | ||
| [System.String] | ||
| # The ID of the target subscription. | ||
| ${SubscriptionId}, | ||
|
|
||
| [Parameter(ParameterSetName='ByResourceId', Mandatory)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Path')] | ||
| [System.String] | ||
| # The ARM Resource ID of the virtual machine. | ||
| ${ResourceId}, | ||
|
|
||
| [Parameter()] | ||
| [Alias('AzureRMContext', 'AzureCredential')] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Azure')] | ||
| [System.Management.Automation.PSObject] | ||
| # The credentials, account, tenant, and subscription used for communication with Azure. | ||
| ${DefaultProfile}, | ||
|
|
||
| [Parameter()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| # Run the command as a job | ||
| ${AsJob}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| # Wait for .NET debugger to attach | ||
| ${Break}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Runtime.SendAsyncStep[]] | ||
| # SendAsync Pipeline Steps to be appended to the front of the pipeline | ||
| ${HttpPipelineAppend}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Runtime.SendAsyncStep[]] | ||
| # SendAsync Pipeline Steps to be prepended to the front of the pipeline | ||
| ${HttpPipelinePrepend}, | ||
|
|
||
| [Parameter()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| # Run the command asynchronously | ||
| ${NoWait}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Uri] | ||
| # The URI for the proxy server to use | ||
| ${Proxy}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Management.Automation.PSCredential] | ||
| # Credentials for a proxy server to use for the remote call | ||
| ${ProxyCredential}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.StackHCIVM.Category('Runtime')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| # Use the default credentials for the proxy | ||
| ${ProxyUseDefaultCredentials} | ||
|
|
||
| ) | ||
| if (($ResourceId -match $vmRegex) -or ($name -and $resourceGroupName -and $subscriptionId)){ | ||
| if ($ResourceId -match $vmRegex){ | ||
| $subscriptionId = $($Matches['subscriptionId']) | ||
| $resourceGroupName = $($Matches['resourceGroupName']) | ||
| $name = $($Matches['machineName']) | ||
| } | ||
| $resourceUri = "/subscriptions/" + $subscriptionId + "/resourceGroups/" + $resourceGroupName + "/providers/Microsoft.HybridCompute/machines/" + $name | ||
| $PSBoundParameters.Add("ResourceUri", $resourceUri) | ||
| $null = $PSBoundParameters.Remove("SubscriptionId") | ||
| $null = $PSBoundParameters.Remove("ResourceGroupName") | ||
| $null = $PSBoundParameters.Remove("ResourceId") | ||
| $null = $PSBoundParameters.Remove("Name") | ||
|
|
||
| if ($PSCmdlet.ShouldProcess($resourceUri, "Suspend virtual machine")) { | ||
| try{ | ||
| Az.StackHCIVM.internal\Suspend-AzStackHCIVMVirtualMachine -ErrorAction Stop @PSBoundParameters | ||
| } catch { | ||
| $e = $_ | ||
| if ($e.FullyQualifiedErrorId -match "MissingAzureKubernetesMapping" ){ | ||
| Write-Error "An older version of the Arc VM cluster extension is installed on your cluster. Please downgrade the Az.StackHCIVm version to 1.0.1 to proceed." -ErrorAction Stop | ||
| } else { | ||
|
Comment on lines
+141
to
+143
|
||
| Write-Error -ErrorRecord $e -ErrorAction Stop | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } else { | ||
| Write-Error "One or more input parameters are invalid. Resource ID is: $ResourceId, name is $name, resource group name is $resourceGroupName, subscription id is $subscriptionid" -ErrorAction Stop | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing -ImagePath from String to SecureString is a breaking change for existing scripts (PowerShell won't implicitly convert a string path to SecureString). If the goal is secret-handling, consider keeping -ImagePath as String (paths aren’t secrets) or supporting both types (e.g., an additional parameter or argument transformation), and regenerate help/examples accordingly.