@@ -42,7 +42,7 @@ function Get-MonkeyAzVMScaleSet {
4242 [Parameter (Mandatory = $false , HelpMessage = " Background Collector ID" )]
4343 [string ]$collectorId
4444 )
45- begin {
45+ Begin {
4646 # Collector metadata
4747 $monkey_metadata = @ {
4848 Id = " az00053" ;
@@ -52,7 +52,7 @@ function Get-MonkeyAzVMScaleSet {
5252 resourceName = $null ;
5353 collectorName = " Get-MonkeyAzVMScaleSet" ;
5454 ApiType = " resourceManagement" ;
55- description = " Collector to get information about Redis instances from Azure" ;
55+ description = " Collector to get information about Virtual Machines ScaleSet from Azure" ;
5656 Group = @ (
5757 " VirtualMachines"
5858 );
@@ -74,25 +74,23 @@ function Get-MonkeyAzVMScaleSet {
7474 # Get Config
7575 $AzureVMScaleConfig = $O365Object.internal_config.ResourceManager | Where-Object { $_.Name -eq " azureVMScaleSet" } | Select-Object - ExpandProperty resource
7676 # Get vm instances
77- $vms = $O365Object.all_resources.Where ({ $_.Id -like " *Microsoft.Compute/virtualMachineScaleSets*" })
78- if (-not $vms ) { continue }
79- $AllVMs = $null
77+ $vmScaleSets = $O365Object.all_resources.Where ({$_.type -match ' ^Microsoft\.Compute/virtualMachineScaleSets$' });
8078 }
81- process {
82- $msg = @ {
83- MessageData = ( $message .MonkeyGenericTaskMessage -f $collectorId , " Azure Virtual Machine scale set " , $O365Object .current_subscription.displayName );
84- callStack = (Get-PSCallStack | Select-Object - First 1 );
85- logLevel = ' info ' ;
86- InformationAction = $O365Object .InformationAction ;
87- Tags = @ ( ' AzureVMInfo ' ) ;
88- }
89- Write-Information @msg
90- if ( $vms ) {
91- $new_arg = @ {
79+ Process {
80+ If ( $vmScaleSets .Count -gt 0 ) {
81+ $msg = @ {
82+ MessageData = ($message .MonkeyGenericTaskMessage -f $collectorId , " Azure Virtual Machine scale set " , $O365Object .current_subscription.displayName );
83+ callStack = ( Get-PSCallStack | Select-Object - First 1 ) ;
84+ logLevel = ' info ' ;
85+ InformationAction = $O365Object .InformationAction ;
86+ Tags = @ ( ' AzureVMInfo ' );
87+ }
88+ Write-Information @msg
89+ $new_arg = @ {
9290 APIVersion = $AzureVMScaleConfig.api_version ;
9391 }
94- $p = @ {
95- ScriptBlock = { Get-MonkeyAzVMScaleSetInfo - InputObject $_ };
92+ $p = @ {
93+ ScriptBlock = { Get-MonkeyAzVirtualMachineScaleSetInfo - InputObject $_ };
9694 Arguments = $new_arg ;
9795 Runspacepool = $O365Object.monkey_runspacePool ;
9896 ReuseRunspacePool = $true ;
@@ -102,28 +100,26 @@ function Get-MonkeyAzVMScaleSet {
102100 BatchSleep = $O365Object.nestedRunspaces.BatchSleep ;
103101 BatchSize = $O365Object.nestedRunspaces.BatchSize ;
104102 }
105- $AllVMs = $vms | Invoke-MonkeyJob @p
106- }
107- }
108- end {
109- if ($AllVMs ) {
110- $AllVMs.PSObject.TypeNames.Insert (0 , ' Monkey365.Azure.VMScaleSet' )
111- [pscustomobject ]$obj = @ {
112- Data = $AllVMs ;
113- Metadata = $monkey_metadata ;
114- }
115- $returnData.az_vm_scaleSet = $obj ;
116- }
117- else {
118- $msg = @ {
119- MessageData = ($message.MonkeyEmptyResponseMessage -f " Azure Virtual Machine scale set" , $O365Object.TenantID );
120- callStack = (Get-PSCallStack | Select-Object - First 1 );
121- logLevel = " verbose" ;
122- InformationAction = $O365Object.InformationAction ;
123- Tags = @ (' AzureVMEmptyResponse' );
124- Verbose = $O365Object.Verbose ;
125- }
126- Write-Verbose @msg
103+ $AllVMs = $vmScaleSets | Invoke-MonkeyJob @p
104+ If ($AllVMs ) {
105+ $AllVMs.PSObject.TypeNames.Insert (0 , ' Monkey365.Azure.VMScaleSet' )
106+ [pscustomobject ]$obj = @ {
107+ Data = $AllVMs ;
108+ Metadata = $monkey_metadata ;
109+ }
110+ $returnData.az_vm_scaleSet = $obj ;
111+ }
112+ Else {
113+ $msg = @ {
114+ MessageData = ($message.MonkeyEmptyResponseMessage -f " Azure Virtual Machine scale set" , $O365Object.TenantID );
115+ callStack = (Get-PSCallStack | Select-Object - First 1 );
116+ logLevel = " verbose" ;
117+ InformationAction = $O365Object.InformationAction ;
118+ Tags = @ (' AzureVMEmptyResponse' );
119+ Verbose = $O365Object.Verbose ;
120+ }
121+ Write-Verbose @msg
122+ }
127123 }
128124 }
129125}
0 commit comments