From 129404db4d4ecf93c9709bc2a7b6272fd61b3099 Mon Sep 17 00:00:00 2001 From: Ventiler Date: Wed, 18 Jan 2023 17:09:22 +0100 Subject: [PATCH] Update List-HostnamesInContract.ps1 Hi, thanks for the work, but was failing (to me) using PS 7.2 till I added the @() as an array. Hope this helps. --- examples/List-HostnamesInContract.ps1 | 80 +++++++++++++-------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/examples/List-HostnamesInContract.ps1 b/examples/List-HostnamesInContract.ps1 index 403928c5..99e92051 100755 --- a/examples/List-HostnamesInContract.ps1 +++ b/examples/List-HostnamesInContract.ps1 @@ -1,43 +1,43 @@ -#************************************************************************ -# -# Name: List-HostnamesInContract -# Author: S Macleod -# Purpose: Uses PAPI to get all properties in contract and list hostnames -# Date: 04/02/2019 -# Version: 1 - Initial -# -#************************************************************************ - -Param( - [Parameter(Mandatory=$false)] [string] $EdgeRCFile = "~\.edgerc", - [Parameter(Mandatory=$false)] [string] $Section = 'default', - [Parameter(Mandatory=$false)] [string] $AccountSwitchKey -) - -if(!(Get-Module AkamaiPowershell)) -{ - Write-Host -ForegroundColor Yellow "Please import the Akamai Powershell module before running this script" - return -} - -$Results = @() -$Properties = Get-AllProperties -Section $Section -AccountSwitchKey $AccountSwitchKey -Write-Host -ForegroundColor yellow "Found $($Properties.Count) properties" - -foreach($Property in $Properties) -{ - $PropHostnames = List-PropertyHostnames -GroupID $Property.groupId -ContractId $Property.contractId -PropertyId $Property.propertyId -PropertyVersion $Property.LatestVersion -Section $Section -AccountSwitchKey $AccountSwitchKey - $PropHostnames | foreach { - #$Results += @{ "Property" = $Property.propertyName; "Hostname" = $_.cnameFrom} - $Result = New-Object -TypeName PSObject - $Result | Add-Member -MemberType NoteProperty -Name "Property" -Value $Property.propertyName - $Result | Add-Member -MemberType NoteProperty -Name "Hostname" -Value $_.cnameFrom - $Results += $Result - } -} - -Write-Host -ForegroundColor Yellow "Found $($results.Count) hosts" -return $Results +#************************************************************************ +# +# Name: List-HostnamesInContract +# Author: S Macleod +# Purpose: Uses PAPI to get all properties in contract and list hostnames +# Date: 04/02/2019 +# Version: 1 - Initial +# +#************************************************************************ + +Param( + [Parameter(Mandatory=$false)] [string] $EdgeRCFile = "~\.edgerc", + [Parameter(Mandatory=$false)] [string] $Section = 'default', + [Parameter(Mandatory=$false)] [string] $AccountSwitchKey +) + +if(!(Get-Module AkamaiPowershell)) +{ + Write-Host -ForegroundColor Yellow "Please import the Akamai Powershell module before running this script" + return +} + +$Results = @() +$Properties = Get-AllProperties -Section $Section -AccountSwitchKey $AccountSwitchKey +Write-Host -ForegroundColor yellow "Found $($Properties.Count) properties" + +foreach($Property in $Properties) +{ + $PropHostnames = @(List-PropertyHostnames -GroupID $Property.groupId -ContractId $Property.contractId -PropertyId $Property.propertyId -PropertyVersion $Property.LatestVersion -Section $Section -AccountSwitchKey $AccountSwitchKey) + $PropHostnames | foreach { + #$Results += @{ "Property" = $Property.propertyName; "Hostname" = $_.cnameFrom} + $Result = New-Object -TypeName PSObject + $Result | Add-Member -MemberType NoteProperty -Name "Property" -Value $Property.propertyName + $Result | Add-Member -MemberType NoteProperty -Name "Hostname" -Value $_.cnameFrom + $Results += $Result + } +} + +Write-Host -ForegroundColor Yellow "Found $($results.Count) hosts" +return $Results # SIG # Begin signature block # MIIp0wYJKoZIhvcNAQcCoIIpxDCCKcACAQExDzANBglghkgBZQMEAgEFADB5Bgor