New-Object for an array of object

Greetings,

I’m trying to put together a simple script for GeoCoding (Location info) and i’m having issues getting the output correct. It’s doing almost what i expect but it’s putting multiple names as one string in the Names property field. I would like separate output for each location. Here’s the script –

$Location = “Some Location”

#########################################

#Get Coordinates of set location

$Business = “$Location” | Get-GeoCoding

$NB = Get-NearbyPlace -Coordinates $Business.Coordinates

ForEach($N in $NB){

$Properties = @{

‘Name’ = $NB.Name;

‘Address’ = $NB.Address;

‘Country’ = $Business.Country;

‘State’ = $Business.State;

‘ZIP’ = $Business.PostalCode

}

$object = New-Object –TypeName PSObject –Prop $Properties

}

and for output i’m getting –

ZIP : 1234

State : Some State

Name : {SomeLocation, Subway, Location3, SomeHotel…}

Address : System.Object&, mscorlib, Version=4.0.0.0, Culture=neutral

Country : United States

What am i doing wrong here?

Thanks in advance!

submitted by /u/Last_Stable
[link] [comments]

Leave a Reply