Skip to content
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

Add get dtl VNet function #664

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion samples/DevTestLabs/Modules/Library/Az.DevTestLabs2.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,43 @@ function Set-AzDtlLabSharedImageGallery {
}
}

function Get-AzDtlVirtualNetworks {
[CmdletBinding()]
param(
[parameter(Mandatory=$true, ValueFromPipeline=$true, HelpMessage="Lab object to get the Virtual Network from")]
[ValidateNotNullOrEmpty()]
$Lab,

[parameter(Mandatory=$false, ValueFromPipeline=$true, HelpMessage="If set, get the Expanded Resource from the std VNet object")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a value from the pipeline? I think only the Lab would be brought in via the pipeline?

$ExpandResource
)

begin {. BeginPreamble}
process {
try {
foreach($lab in $Lab) {

$lab = $lab | Get-AzDtlLab

$dtlLabVNets = Get-AzureRmResource `
-ResourceGroupName $lab.ResourceGroupName `
-ResourceType Microsoft.DevTestLab/labs/virtualnetworks `
-ResourceName $lab.Name `
-ApiVersion 2018-09-15

if ($ExpandResource) {
foreach($dtlLabVNet in $dtlLabVNets) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use a more PowerShell-like syntax here like $dtlLabVNets | ForEach-Object { .... }

Get-AzureRmVirtualNetwork -ResourceGroupName $dtlLabVNet.ResourceGroupName -Name $dtlLabVNet.Name -ExpandResource $ExpandResource
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If ExpandResource isn't passed in - does anything get returned from this commandlet? I would think we should have the Lab VNets always returned, and if ExpandResource is passed in, we can inject another property that contains the underlying VNet resource? There's an example for Getting VMs & Extended status in the library...

}
}
}
} catch {
Write-Error -ErrorRecord $_ -EA $callerEA
}
}
end {}
}

function Get-AzDtlLabSharedImageGalleryImages {
[CmdletBinding()]
param(
Expand Down Expand Up @@ -3183,6 +3220,8 @@ New-Alias -Name 'UnClaim-AzureRmDtlVm' -Value Invoke-AzDtlVmUnClaim
New-Alias -Name 'Dtl-NewEnvironment' -Value New-AzDtlLabEnvironment
New-Alias -Name 'Dtl-GetEnvironment' -Value Get-AzDtlLabEnvironment

New-Alias -Name 'Dtl-GetVirtualNetworks' -Value Get-AzDtlVirtualNetworks

Export-ModuleMember -Function New-AzDtlLab,
Remove-AzDtlLab,
Get-AzDtlLab,
Expand Down Expand Up @@ -3220,7 +3259,8 @@ Export-ModuleMember -Function New-AzDtlLab,
Get-AzDtlVmArtifact,
Import-AzDtlCustomImageFromUri,
Get-AzDtlCustomImage,
New-AzDtlCustomImageFromVm
New-AzDtlCustomImageFromVm,
Get-AzDtlVirtualNetworks

Export-ModuleMember -Alias *
#endregion