I'm very new to PowerHell, and am simply trying to create an (inline) function that will take-in various parameters and return a populated array. However, I keep getting the following error:
ERROR:
You cannot call a method on a null-valued expression.
At EnumerateSites.ps1:157 char:19
+ $Array.Add <<<< ($groupName)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
THE CODE LOOKS LIKE:
The "Title" variables all have valid values.
$ValidSecurityGroupSuffixes = @("Suffix A", "Suffix B", "Suffix C")
$ExpectedSecurityGroups = CreateSecurityGroupList($SPSiteCollection.RootWeb.Title, $SPWeb.Title, $ValidSecurityGroupSuffixes)
function CreateSecurityGroupList ([string] $siteCollectionName, [string] $siteName, [string[]] $suffixes)
{
$Array = $()
foreach($suffix in $suffixes)
{
$groupName = $siteCollectionName + " - " + $siteName + " - " + $suffix
$Array.Add($groupName)
}
$Array
}
ADDITIONALLY:
When I commented-out some things and just printed the variables within the Functions ForEach Loop, I get this...
"SomeCustomerName SomeSiteName System.Object[] - - "
I should be getting this...
"CustomerName - Location - Suffix A"
"CustomerName - Location - Suffix B"
"CustomerName - Location - Suffix C"
Any insight is appreciated.