1
0
Fork 0

Rewrite types of return values

master
Andrey Prokhorov 5 years ago
parent 0d1b705ef3
commit d8075fa05c

@ -59,7 +59,7 @@ function Get-ACSUserByName {
) )
$resturl = "/Rest/Identity/User/name/" $resturl = "/Rest/Identity/User/name/"
$result = Invoke-WebRequest -UseBasicParsing -WebSession $session -Method GET -Uri "$($acs)$($resturl)$($username)" $result = Invoke-WebRequest -UseBasicParsing -WebSession $session -Method GET -Uri "$($acs)$($resturl)$($username)"
return $result.Content return [xml]$result.Content
} }
# Get devices that are conform with supplied filter (in XML format) # Get devices that are conform with supplied filter (in XML format)
@ -72,7 +72,7 @@ function Get-FilterDevicesByName {
$header = @{"Content-type" = "application/xml"} $header = @{"Content-type" = "application/xml"}
$resturl = "/Rest/NetworkDevice/Device/op/query" $resturl = "/Rest/NetworkDevice/Device/op/query"
$result = Invoke-WebRequest -UseBasicParsing -WebSession $session -Method PUT -Uri "$($acs)$($resturl)" -Body $filter -Headers $header $result = Invoke-WebRequest -UseBasicParsing -WebSession $session -Method PUT -Uri "$($acs)$($resturl)" -Body $filter -Headers $header
return $result.Content return [xml]$result.Content
} }
# Get locations list (either all, or that match $filter) # Get locations list (either all, or that match $filter)
@ -92,7 +92,7 @@ function Get-AllLocations {
$resturl = "/Rest/NetworkDevice/DeviceGroup/op/query" $resturl = "/Rest/NetworkDevice/DeviceGroup/op/query"
$result = Invoke-WebRequest -UseBasicParsing -WebSession $session -Method PUT -Uri "$($acs)$($resturl)" -Headers $header -Body $filter $result = Invoke-WebRequest -UseBasicParsing -WebSession $session -Method PUT -Uri "$($acs)$($resturl)" -Headers $header -Body $filter
} }
return $result.Content return [xml]$result.Content
} }
# Get all devices (XML) assigned to $location and save XML to files # Get all devices (XML) assigned to $location and save XML to files
@ -117,12 +117,8 @@ function Get-DevicesByLocation {
# Query devices # Query devices
$result = Invoke-WebRequest -UseBasicParsing -WebSession $session -Method PUT -Uri "$($acs)$($resturl)" -Headers $header -Body $filter $result = Invoke-WebRequest -UseBasicParsing -WebSession $session -Method PUT -Uri "$($acs)$($resturl)" -Headers $header -Body $filter
# Format result
$result.Content | Set-Content -Path tmp_devices.xml
$parsed = [xml](Get-Content tmp_devices.xml)
# Loop thru all received devices # Loop thru all received devices
$devs = Select-Xml -xml $parsed -XPath //Device $devs = Select-Xml -xml $result -XPath //Device
foreach ($dev in $devs) { foreach ($dev in $devs) {
"`t$($dev.node.id);$($dev.node.name);$($dev.node.subnets.ipAddress)" | Out-Host "`t$($dev.node.id);$($dev.node.name);$($dev.node.subnets.ipAddress)" | Out-Host
} }
@ -177,7 +173,7 @@ function Get-LocationIDByName {
) )
$resturl = "/Rest/NetworkDevice/DeviceGroup/name/Location:$($location)" $resturl = "/Rest/NetworkDevice/DeviceGroup/name/Location:$($location)"
$result = Invoke-WebRequest -UseBasicParsing -WebSession $session -Method GET -Uri "$($acs)$($resturl)" $result = Invoke-WebRequest -UseBasicParsing -WebSession $session -Method GET -Uri "$($acs)$($resturl)"
return $result.Content return [xml]$result.Content
} }
# Find device by Name and return its XML # Find device by Name and return its XML
@ -197,7 +193,7 @@ function Get-DeviceByName {
"Error occured during data retrieval for $($name)" | Write-Host "Error occured during data retrieval for $($name)" | Write-Host
return return
} }
return $result.Content return [xml]$result.Content
} }
# Delete location by its ID # Delete location by its ID

Loading…
Cancel
Save