Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepowershell
titleFor each device, get hostname, ram, cpu
collapsetrue
$count = 0
$uri_a = 'http://vm-mike-2k12a.iqdomain.com/api/v1/devices/?offset='
$uri_b = '&fetch_size=1'

# This is going to hold the CSV file, let's build the header row
$csv = @() 
$row = New-Object System.Object
$row | Add-Member -MemberType NoteProperty -Name "Host" -Value $null
$row | Add-Member -MemberType NoteProperty -Name "RAM" -Value $null
$row | Add-Member -MemberType NoteProperty -Name "CPU Type" -Value $null


while ($count -le $deviceCount)
{	
	# Build the URL
	$count = $count + 1
	$url =  -join ($uri_a, $count, $uri_b )
	$dev = Invoke-RestMethod $url -Credential $credential
	
	$row = New-Object System.Object
	# Put the hostname in to the row
	$row | Add-Member -MemberType NoteProperty -Name "Host" -Value $dev.host_name ; 
	# Get the link to the rest of the details	
	$url2 = $dev.self	
	$device = Invoke-RestMethod $url2 -Credential $credential
	
	$row | Add-Member -MemberType NoteProperty -Name "RAM" -Value device.total_memory_mb
	$row | Add-Member -MemberType NoteProperty -Name "CPU Type" -Value $device.cpu.cpu_model
	$csv += $row
	# display progress
	write-host "." -nonewline
}

...

Page Properties
hiddentrue


Related issues