-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvmsslist.ps1
More file actions
41 lines (28 loc) · 1.51 KB
/
vmsslist.ps1
File metadata and controls
41 lines (28 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Developed by GEVIVESH
#Use by your own risk
#Educational Purposes
$subscriptionid = "ABCD-ADDSAD-DSADD-FFFF"
$ResourceGroup = "RGNAME"
$VMSSName = "VMSS"
$token = (Get-AzAccessToken).Token # We are using Azure Powershell module to get the Token you can get it from another place ;)
#creating the header
$authHeader = @{
'Authorization' = 'Bearer ' + $token
'Content-Type' = 'application/json'
}
$restUri = "https://management.azure.com/subscriptions/" +$subscriptionid+"/resourceGroups/" +$ResourceGroup + "/providers/Microsoft.Compute/virtualMachineScaleSets/" + $VMSSName + "/virtualMachines?api-version=2023-07-01"
$body = ($requestbody | ConvertTo-Json)
$response = Invoke-RestMethod -Uri $restUri -Method Get -Headers $authHeader -Body $body
#----------------------------------------
$table = @()
foreach($instance in $response.value){
$res = New-Object -TypeName psobject
$res | Add-Member -MemberType NoteProperty -Name PlatFormName -Value $instance.name -Force
$restUri = "https://management.azure.com" + "/subscriptions/" + $subscriptionid + "/resourceGroups/" + $ResourceGroup + "/providers/Microsoft.Compute/virtualMachines/" + $instance.name + "?api-version=2023-07-01"
$body = ($requestbody | ConvertTo-Json)
$response = Invoke-RestMethod -Uri $restUri -Method Get -Headers $authHeader -Body $body
$ComputerName = $response.properties.osProfile.computerName
$res | Add-Member -MemberType NoteProperty -Name Name -Value $Computername -Force
$table += $res
}
$table | FT