diff --git a/Edition-01/Examples/The AAA Approach/Example 1.ps1 b/Edition-01/Examples/The AAA Approach/Example 1.ps1 index 15a7288..7a72632 100644 --- a/Edition-01/Examples/The AAA Approach/Example 1.ps1 +++ b/Edition-01/Examples/The AAA Approach/Example 1.ps1 @@ -1,23 +1,20 @@ -$swApiUrl = 'https://mc-starwars-data.azurewebsites.net' -function Invoke-StarWarsApi -{ +$swApiUrl = 'https://swapi.info' +function Invoke-StarWarsApi { param ( [Parameter(Mandatory)] [ValidateSet('Planets', 'Films', 'People')] - [string] $ObjectType, + [string]$objectType, - [int] $id = -1 + [int]$id = -1 ) try { - $suffix = $id -ne -1 ? "?id=$id" : "" + $suffix = $id -ne -1 ? "/$id" : '' $path = "$($objectType.ToLower())$suffix" $output = Invoke-RestMethod -Uri "$swApiUrl/api/$path" -Method GET Write-Output $output - } - catch { + } catch { $msg = "Error calling $swApiUrl/api/$path. $($_.Exception.Message)" Write-Host $msg -f Red - Write-Output $null } } diff --git a/Edition-01/Examples/The AAA Approach/Example 10.txt b/Edition-01/Examples/The AAA Approach/Example 10.txt index d206aff..f589624 100644 --- a/Edition-01/Examples/The AAA Approach/Example 10.txt +++ b/Edition-01/Examples/The AAA Approach/Example 10.txt @@ -10,7 +10,7 @@ Describing Get-SWPerson [+] Returns person metadata for 'Darth Maul' with gender 'male', eye colour 'yellow' & film count of 1 3.96s (3.96s|5ms) [+] Returns person metadata for 'Luke Skywalker' with gender 'male', - eye colour 'blue' & film count of 6 4.37s (4.37s|2ms) + eye colour 'blue' & film count of 4 4.37s (4.37s|2ms) [+] Returns person metadata for 'Mon Mothma' with gender 'female', eye colour 'blue' & film count of 1 4.19s (4.19s|3ms) Tests completed in 16.11s diff --git a/Edition-01/Examples/The AAA Approach/Example 2.ps1 b/Edition-01/Examples/The AAA Approach/Example 2.ps1 index 4831cb0..899d32c 100644 --- a/Edition-01/Examples/The AAA Approach/Example 2.ps1 +++ b/Edition-01/Examples/The AAA Approach/Example 2.ps1 @@ -1,29 +1,20 @@ function Search-SWPerson { param ( [Parameter(Mandatory)] - [string] $Name + [string]$Name ) # load all the people $response = Invoke-StarWarsApi -objectType People # filter on the name - $results = $response | Where-Object name -like "*$Name*" + $results = $response | Where-Object name -Like "*$Name*" if ($null -eq $results) { - Write-Output @{ Error = "No person results found for '$Name'."} - } - else { + Write-Output @{ Error = "No person results found for '$Name'." } + } else { # return all matches with some properties - $personDetails = $results | ForEach-Object { - Invoke-StarWarsApi -objectType People -id $_.id - } - - Write-Output $personDetails | Select-Object @{ - Name = "id"; - Expression = { $_.id} + Write-Output $results | Select-Object @{ + Name = 'id'; Expression = { $_.url | Get-SWIdFromUrl } }, name, gender, height, - @{ - Name = "weight" - Expression = {$_.mass} - } + @{ Name = 'weight'; Expression = { $_.mass } } } } diff --git a/Edition-01/Examples/The AAA Approach/Example 3.ps1 b/Edition-01/Examples/The AAA Approach/Example 3.ps1 index 66daa2f..55f6545 100644 --- a/Edition-01/Examples/The AAA Approach/Example 3.ps1 +++ b/Edition-01/Examples/The AAA Approach/Example 3.ps1 @@ -1,36 +1,30 @@ function Get-SWPerson { param ( [Parameter(Mandatory)] - [int] $Id + [int]$Id ) # get the person $person = Invoke-StarWarsApi -objectType People -id $Id - if ($null -eq $person) - { - Write-Output @{ - Error = "Unable to find a person record given Id: $Id" + if ($null -eq $person) { + Write-Output @{ + Error = "Unable to find a person record given Id: $id" } - } - else { + } else { # get the homeworld planet and the films - $planet = Invoke-StarWarsApi -objectType Planets -id $person.homeworld + $HomeWorldId = $person.homeworld | Get-SWIdFromUrl + $planet = Invoke-StarWarsApi -objectType Planets -id $HomeWorldId $films = Invoke-StarWarsApi -objectType Films - # get detailed info of all films - $filmDetails = $films | ForEach-Object { - Invoke-StarWarsApi -objectType Films -id $_.id - } - # build the result object as a mix of all the data returned $result = [PSCustomObject]@{ - Name = $person.Name - BodyType = $person | + Name = $person.Name + BodyType = $person | Select-Object height, mass, gender, skin_color, eye_color HomeWorld = $planet | Select-Object name, population, gravity, terrain - Films = $filmDetails | - Where-Object people -contains $person.id | + Films = $films | + Where-Object characters -Contains $person.url | Select-Object title, director, release_date } Write-Output $result diff --git a/Edition-01/Examples/The AAA Approach/Example 5.ps1 b/Edition-01/Examples/The AAA Approach/Example 5.ps1 index 2f48a81..8b4fc05 100644 --- a/Edition-01/Examples/The AAA Approach/Example 5.ps1 +++ b/Edition-01/Examples/The AAA Approach/Example 5.ps1 @@ -1 +1 @@ -Get-SWPerson -Id 9 | Format-List +Get-SWPerson -Id 11 | Format-List diff --git a/Edition-01/Examples/The AAA Approach/Example 6.ps1 b/Edition-01/Examples/The AAA Approach/Example 6.ps1 index 342909d..0cc73d7 100644 --- a/Edition-01/Examples/The AAA Approach/Example 6.ps1 +++ b/Edition-01/Examples/The AAA Approach/Example 6.ps1 @@ -1,6 +1,6 @@ # Arrange BeforeAll { - . $PSCommandPath.Replace('.Simple.Tests.ps1','.ps1') + . $PSCommandPath.Replace('.Simple.Tests.ps1', '.ps1') } Describe 'Search-SWPerson' -Tag 'Unit' { diff --git a/Edition-01/Examples/The AAA Approach/Example 8.ps1 b/Edition-01/Examples/The AAA Approach/Example 8.ps1 index 3661137..b7f2337 100644 --- a/Edition-01/Examples/The AAA Approach/Example 8.ps1 +++ b/Edition-01/Examples/The AAA Approach/Example 8.ps1 @@ -1,6 +1,6 @@ # Arrange BeforeAll { - . $PSCommandPath.Replace('.Mocked.Tests.ps1','.ps1') + . $PSCommandPath.Replace('.Mocked.Tests.ps1', '.ps1') Mock Invoke-StarWarsApi { $output1 = [PSCustomObject]@{ @@ -25,4 +25,4 @@ BeforeAll { weight = '84' } Write-Output @($output1, $output2, $output3) - } -Verifiable -ParameterFilter { $objectType -eq 'People'} + } -Verifiable -ParameterFilter { $objectType -eq 'People' } diff --git a/Edition-01/Examples/The AAA Approach/Example 9.ps1 b/Edition-01/Examples/The AAA Approach/Example 9.ps1 index 969abfb..7e6e29b 100644 --- a/Edition-01/Examples/The AAA Approach/Example 9.ps1 +++ b/Edition-01/Examples/The AAA Approach/Example 9.ps1 @@ -1,6 +1,6 @@ # Arrange BeforeAll { - . $PSCommandPath.Replace('.Complex.Tests.ps1','.ps1') + . $PSCommandPath.Replace('.Complex.Tests.ps1', '.ps1') } Describe 'Search-SWFilm' -Tag 'Unit' { @@ -10,23 +10,23 @@ Describe 'Search-SWFilm' -Tag 'Unit' { It $itName -TestCases @( # Arrange @{ - name = 'Phantom' - year = '1999-05-19' + name = 'Phantom' + year = '1999-05-19' director = 'George Lucas' } @{ - name = 'Empire' - year = '1980-05-17' + name = 'Empire' + year = '1980-05-17' director = 'Irvin Kershner' } @{ - name = 'Return' - year = '1983-05-25' + name = 'Return' + year = '1983-05-25' director = 'Richard Marquand' } - ) { + ) { # Act - $result = Search-SWFilm -name $name + $result = Search-SWFilm -Name $name # Assert $result.Count | Should -Be 1 diff --git a/Edition-01/Starwars-Demo/src/StarWarsData.Complex.Tests.ps1 b/Edition-01/Starwars-Demo/src/StarWarsData.Complex.Tests.ps1 index a21376c..42462f6 100644 --- a/Edition-01/Starwars-Demo/src/StarWarsData.Complex.Tests.ps1 +++ b/Edition-01/Starwars-Demo/src/StarWarsData.Complex.Tests.ps1 @@ -1,81 +1,81 @@ # Arrange BeforeAll { - . $PSCommandPath.Replace('.Complex.Tests.ps1', '.ps1') + . $PSCommandPath.Replace('.Complex.Tests.ps1', '.ps1') } Describe 'Search-SWFilm' -Tag 'Unit' { - $itName = "Returns film with release date '' & director " + - "'' given title fragment ''" - It $itName -TestCases @( - # Arrange - @{ - name = 'Phantom' - year = '1999-05-19' - director = 'George Lucas' - } - @{ - name = 'Empire' - year = '1980-05-17' - director = 'Irvin Kershner' - } - @{ - name = 'Return' - year = '1983-05-25' - director = 'Richard Marquand' - } - ) { - # Act - $result = Search-SWFilm -name $name + $itName = "Returns film with release date '' & director " + + "'' given title fragment ''" + It $itName -TestCases @( + # Arrange + @{ + name = 'Phantom' + year = '1999-05-19' + director = 'George Lucas' + } + @{ + name = 'Empire' + year = '1980-05-17' + director = 'Irvin Kershner' + } + @{ + name = 'Return' + year = '1983-05-25' + director = 'Richard Marquand' + } + ) { + # Act + $result = Search-SWFilm -Name $name - # Assert - $result.Count | Should -Be 1 - $result.title | Should -BeLike "*$name*" - $result.release_date | Should -Be $year - $result.director | Should -Be $director - } + # Assert + $result.Count | Should -Be 1 + $result.title | Should -BeLike "*$name*" + $result.release_date | Should -Be $year + $result.director | Should -Be $director + } } Describe 'Get-SWPerson' -Tag 'Unit' { - $itName = "Returns person metadata for '' with gender " + - "'', eye colour '' & film count of " - It $itName -TestCases @( - # Arrange - @{ - name = 'maul' - fullName = 'Darth Maul' - gender = 'male' - eyeColour = 'yellow' - homeWorld = 'Dathomir' - filmCount = 1 - } - @{ - name = 'luke' - fullName = 'Luke Skywalker' - gender = 'male' - eyeColour = 'blue' - homeWorld = 'Tatooine' - filmCount = 6 - } - @{ - name = 'mothma' - fullName = 'Mon Mothma' - gender = 'female' - eyeColour = 'blue' - homeWorld = 'Chandrila' - filmCount = 1 - } - ) { - # Act - $result = Search-SWPerson -name $name - $result.Count | Should -Be 1 - $details = Get-SWPerson -Id $result.Id + $itName = "Returns person metadata for '' with gender " + + "'', eye colour '' & film count of " + It $itName -TestCases @( + # Arrange + @{ + name = 'maul' + fullName = 'Darth Maul' + gender = 'male' + eyeColour = 'yellow' + homeWorld = 'Dathomir' + filmCount = 1 + } + @{ + name = 'luke' + fullName = 'Luke Skywalker' + gender = 'male' + eyeColour = 'blue' + homeWorld = 'Tatooine' + filmCount = 4 + } + @{ + name = 'mothma' + fullName = 'Mon Mothma' + gender = 'female' + eyeColour = 'blue' + homeWorld = 'Chandrila' + filmCount = 1 + } + ) { + # Act + $result = Search-SWPerson -Name $name + $result.Count | Should -Be 1 + $details = Get-SWPerson -Id $result.Id - # Assert - $details | Should -Not -BeNullOrEmpty - $details.Name | Should -Be $fullName - $details.BodyType.gender | Should -Be $gender - $details.BodyType.eye_color | Should -Be $eyeColour - $details.HomeWorld.name | Should -Be $homeWorld - $details.Films | Should -HaveCount $filmCount - } -} \ No newline at end of file + # Assert + $details | Should -Not -BeNullOrEmpty + $details.Name | Should -Be $fullName + $details.BodyType.gender | Should -Be $gender + $details.BodyType.eye_color | Should -Be $eyeColour + $details.HomeWorld.name | Should -Be $homeWorld + $details.Films | Should -HaveCount $filmCount + } +} diff --git a/Edition-01/Starwars-Demo/src/StarWarsData.Mocked.Tests.ps1 b/Edition-01/Starwars-Demo/src/StarWarsData.Mocked.Tests.ps1 index d7e0396..f5344e8 100644 --- a/Edition-01/Starwars-Demo/src/StarWarsData.Mocked.Tests.ps1 +++ b/Edition-01/Starwars-Demo/src/StarWarsData.Mocked.Tests.ps1 @@ -1,8 +1,8 @@ # Arrange BeforeAll { - . $PSCommandPath.Replace('.Mocked.Tests.ps1','.ps1') + . $PSCommandPath.Replace('.Mocked.Tests.ps1', '.ps1') - Mock Invoke-StarWarsApi { + Mock Invoke-StarWarsApi { $output1 = [PSCustomObject]@{ id = 4 name = 'Darth Vader' @@ -25,9 +25,9 @@ BeforeAll { weight = '84' } Write-Output @($output1, $output2, $output3) - } -Verifiable -ParameterFilter { $objectType -eq 'People'} + } -Verifiable -ParameterFilter { $objectType -eq 'People' } - Mock Invoke-StarWarsApi { + Mock Invoke-StarWarsApi { $output = [PSCustomObject]@{ height = '172' mass = '77' @@ -41,9 +41,9 @@ BeforeAll { id = 1 } Write-Output @($output) - } -Verifiable -ParameterFilter { $objectType -eq 'People' -and $id -eq 1} + } -Verifiable -ParameterFilter { $objectType -eq 'People' -and $id -eq 1 } - Mock Invoke-StarWarsApi { + Mock Invoke-StarWarsApi { $output = [PSCustomObject]@{ height = '202' mass = '136' @@ -57,9 +57,9 @@ BeforeAll { id = 4 } Write-Output @($output) - } -Verifiable -ParameterFilter { $objectType -eq 'People' -and $id -eq 4} + } -Verifiable -ParameterFilter { $objectType -eq 'People' -and $id -eq 4 } - Mock Invoke-StarWarsApi { + Mock Invoke-StarWarsApi { $output = [PSCustomObject]@{ height = '188' mass = '84' @@ -73,9 +73,9 @@ BeforeAll { id = 9 } Write-Output @($output) - } -Verifiable -ParameterFilter { $objectType -eq 'People' -and $id -eq 9} + } -Verifiable -ParameterFilter { $objectType -eq 'People' -and $id -eq 9 } - Mock Invoke-StarWarsApi { + Mock Invoke-StarWarsApi { $output1 = [PSCustomObject]@{ id = 8 name = 'Naboo' @@ -98,9 +98,9 @@ BeforeAll { terrain = @('oceans', 'savannas', 'mountains', 'grasslands') } Write-Output @($output1, $output2, $output3) - } -Verifiable -ParameterFilter { $objectType -eq 'Planets'} + } -Verifiable -ParameterFilter { $objectType -eq 'Planets' } - Mock Invoke-StarWarsApi { + Mock Invoke-StarWarsApi { $output = [PSCustomObject]@{ diameter = '12120' rotation_period = '26' @@ -113,9 +113,9 @@ BeforeAll { id = 8 } Write-Output @($output) - } -Verifiable -ParameterFilter { $objectType -eq 'Planets' -and $id -eq 8} + } -Verifiable -ParameterFilter { $objectType -eq 'Planets' -and $id -eq 8 } - Mock Invoke-StarWarsApi { + Mock Invoke-StarWarsApi { $output = [PSCustomObject]@{ diameter = '10465' rotation_period = '23' @@ -128,9 +128,9 @@ BeforeAll { id = 1 } Write-Output @($output) - } -Verifiable -ParameterFilter { $objectType -eq 'Planets' -and $id -eq 1} + } -Verifiable -ParameterFilter { $objectType -eq 'Planets' -and $id -eq 1 } - Mock Invoke-StarWarsApi { + Mock Invoke-StarWarsApi { $output = [PSCustomObject]@{ diameter = '9830' rotation_period = '25' @@ -143,14 +143,14 @@ BeforeAll { id = 25 } Write-Output @($output) - } -Verifiable -ParameterFilter { $objectType -eq 'Planets' -and $id -eq 25} + } -Verifiable -ParameterFilter { $objectType -eq 'Planets' -and $id -eq 25 } } Describe 'Search-SWPerson' -Tag 'Unit', 'Mocked' { It 'Returns a single match' { # Arrange $testName = 'Vader' - + # Act $result = Search-SWPerson -Name $testName @@ -168,7 +168,7 @@ Describe 'Search-SWPerson' -Tag 'Unit', 'Mocked' { # Assert $result.Error | Should -Be "No person results found for '$testName'." } - It "Returns multiple matches" { + It 'Returns multiple matches' { # Arrange $testName = 'walker' @@ -177,7 +177,7 @@ Describe 'Search-SWPerson' -Tag 'Unit', 'Mocked' { # Assert $result.Count | Should -BeGreaterThan 1 - $result.Name -like "*$testName*"| Should -HaveCount $result.Count + $result.Name -like "*$testName*" | Should -HaveCount $result.Count } } @@ -185,7 +185,7 @@ Describe 'Search-SWPlanet' -Tag 'Unit', 'Mocked' { It 'Returns a single match' { # Arrange $testName = 'nabo' - + # Act $result = Search-SWPlanet -Name $testName @@ -196,7 +196,7 @@ Describe 'Search-SWPlanet' -Tag 'Unit', 'Mocked' { It 'Returns no matches' { # Arrange $testName = 'Invalid' - + # Act $result = Search-SWPlanet -Name $testName @@ -214,4 +214,4 @@ Describe 'Search-SWPlanet' -Tag 'Unit', 'Mocked' { $result.Count | Should -BeGreaterThan 1 $result.Name -like "*$testName*" | Should -HaveCount $result.Count } -} \ No newline at end of file +} diff --git a/Edition-01/Starwars-Demo/src/StarWarsData.Simple.Tests.ps1 b/Edition-01/Starwars-Demo/src/StarWarsData.Simple.Tests.ps1 index 6df0e6f..3bd9c59 100644 --- a/Edition-01/Starwars-Demo/src/StarWarsData.Simple.Tests.ps1 +++ b/Edition-01/Starwars-Demo/src/StarWarsData.Simple.Tests.ps1 @@ -1,6 +1,6 @@ # Arrange BeforeAll { - . $PSCommandPath.Replace('.Simple.Tests.ps1','.ps1') + . $PSCommandPath.Replace('.Simple.Tests.ps1', '.ps1') } Describe 'Search-SWPerson' -Tag 'Unit' { @@ -71,4 +71,4 @@ Describe 'Search-SWPlanet' -Tag 'Unit' { $result.Count | Should -BeGreaterThan 1 $result.Name -like "*$testName*" | Should -HaveCount $result.Count } -} \ No newline at end of file +} diff --git a/Edition-01/Starwars-Demo/src/StarWarsData.ps1 b/Edition-01/Starwars-Demo/src/StarWarsData.ps1 index 6013b3e..dd7f328 100644 --- a/Edition-01/Starwars-Demo/src/StarWarsData.ps1 +++ b/Edition-01/Starwars-Demo/src/StarWarsData.ps1 @@ -1,55 +1,60 @@ -# Wrapper for the Star Wars API website https://swapi-deno.azurewebsites.net +# Wrapper for the Star Wars API website https://swapi.info # # other samples that are out there, in case the above site goes offline -# - www.swapi.tech -# - swapi.dev +# - https://swapi.dev +# - https://www.swapi.tech #Requires -Version 7.0 -$swApiUrl = 'https://mc-starwars-data.azurewebsites.net' -function Invoke-StarWarsApi -{ +$swApiUrl = 'https://swapi.info' +function Invoke-StarWarsApi { param ( [Parameter(Mandatory)] [ValidateSet('Planets', 'Films', 'People')] - [string] $objectType, + [string]$objectType, - [int] $id = -1 + [int]$id = -1 ) try { - $suffix = $id -ne -1 ? "?id=$id" : "" + $suffix = $id -ne -1 ? "/$id" : '' $path = "$($objectType.ToLower())$suffix" $output = Invoke-RestMethod -Uri "$swApiUrl/api/$path" -Method GET Write-Output $output - } - catch { + } catch { $msg = "Error calling $swApiUrl/api/$path. $($_.Exception.Message)" Write-Host $msg -f Red - Write-Output $null } } +# Gets the ID from a Star Wars person, planet, or film URL +function Get-SWIdFromUrl { + param ( + [Parameter(ValueFromPipeline)] + [string]$Url + ) + $Url -replace 'http.+/(\d+).*?', '$1' +} + # Searches for a Star Wars person given a part of a name function Search-SWPerson { param ( [Parameter(Mandatory)] - [string] $Name + [string]$Name ) # load all the people $response = Invoke-StarWarsApi -objectType People # filter on the name - $results = $response | Where-Object name -like "*$Name*" + $results = $response | Where-Object name -Like "*$Name*" if ($null -eq $results) { - Write-Output @{ Error = "No person results found for '$Name'."} - } - else { + Write-Output @{ Error = "No person results found for '$Name'." } + } else { # return all matches with some properties - $personDetails = $results | ForEach-Object { Invoke-StarWarsApi -objectType People -id $_.id } - Write-Output $personDetails | Select-Object @{ Name = "id"; Expression = { $_.id} }, - name, gender, height, - @{ Name = "weight"; Expression = {$_.mass} } + Write-Output $results | Select-Object @{ + Name = 'id'; Expression = { $_.url | Get-SWIdFromUrl } + }, name, gender, height, + @{ Name = 'weight'; Expression = { $_.mass } } } } @@ -57,21 +62,20 @@ function Search-SWPerson { function Search-SWPlanet { param ( [Parameter(Mandatory)] - [string] $Name + [string]$Name ) # load all the planets $response = Invoke-StarWarsApi -objectType Planets # filter on the name - $results = $response | Where-Object name -like "*$Name*" + $results = $response | Where-Object name -Like "*$Name*" if ($null -eq $results) { - Write-Output @{ Error = "No planet results found for '$Name'."} - } - else { - $planetDetails = $results | ForEach-Object { Invoke-StarWarsApi -objectType Planets -id $_.id } + Write-Output @{ Error = "No planet results found for '$Name'." } + } else { # return all matches with some attributes - Write-Output $planetDetails | Select-Object @{ Name = "id"; Expression = {$_.id} }, - name, population, diameter, terrain + Write-Output $results | Select-Object @{ + Name = 'id'; Expression = { $_.url | Get-SWIdFromUrl } + }, name, population, diameter, terrain } } @@ -79,51 +83,51 @@ function Search-SWPlanet { function Search-SWFilm { param ( [Parameter(Mandatory)] - [string] $Name + [string]$Name ) # load all the films (currently does not include the new trilogy) $response = Invoke-StarWarsApi -objectType Films # filter on the name - $results = $response | Where-Object title -like "*$Name*" + $results = $response | Where-Object title -Like "*$Name*" if ($null -eq $results) { - Write-Output @{ Error = "No film results found for '$Name'."} - } - else { + Write-Output @{ Error = "No film results found for '$Name'." } + } else { # return all matches with some attributes - $filmDetails = $results | ForEach-Object { Invoke-StarWarsApi -objectType Films -id $_.id } - Write-Output $filmDetails | Select-Object @{ Name = "id"; Expression = { $_.id} }, - title, director, release_date, - characters, planets + Write-Output $results | Select-Object @{ + Name = 'id'; Expression = { $_.url | Get-SWIdFromUrl } + }, title, director, release_date, characters, planets } } function Get-SWPerson { param ( [Parameter(Mandatory)] - [int] $Id + [int]$Id ) # get the person $person = Invoke-StarWarsApi -objectType People -id $Id - if ($null -eq $person) - { - Write-Output @{ Error = "Unable to find a person record given Id: $Id" } - } - else { + if ($null -eq $person) { + Write-Output @{ + Error = "Unable to find a person record given Id: $id" + } + } else { # get the homeworld planet and the films - $planet = Invoke-StarWarsApi -objectType Planets -id $person.homeworld + $HomeWorldId = $person.homeworld | Get-SWIdFromUrl + $planet = Invoke-StarWarsApi -objectType Planets -id $HomeWorldId $films = Invoke-StarWarsApi -objectType Films - # get detailed info of all films - $filmDetails = $films | ForEach-Object { Invoke-StarWarsApi -objectType Films -id $_.id } - # build the result object as a mix of all the data returned $result = [PSCustomObject]@{ - Name = $person.Name - BodyType = $person | Select-Object height, mass, gender, skin_color, eye_color - HomeWorld = $planet | Select-Object name, population, gravity, terrain - Films = $filmDetails | Where-Object people -contains $person.id | Select-Object title, director, release_date + Name = $person.Name + BodyType = $person | + Select-Object height, mass, gender, skin_color, eye_color + HomeWorld = $planet | + Select-Object name, population, gravity, terrain + Films = $films | + Where-Object characters -Contains $person.url | + Select-Object title, director, release_date } Write-Output $result }