I have a Powershell function that loops through an array and populates attributes to a new Exchange/Office 365 group. The recent challenge that was asked was to prepend certain text to only certain attributes from the inputObject.
Here is the core working function before attempting to prepend the text:
$allObjects = @(Get-ChildItem -path c:\tmp\json\*.json | Get-Content -Raw | ConvertFrom-Json)
function Import-UnixDL2Group {
[CmdletBinding()]
Param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
$InputObject
)
Process{
New-UnifiedGroup -Alias $InputObject.alias `
-DisplayName $InputObject.displayname `
-Members $InputObject.members.recipients.value `
-PrimarySmtpAddress $InputObject.emailaddresses.value `
}
}
$allObjects | Import-UnixDL2Group
So the prepended text needs to occur either before or during the Import-UnixDL2Group function.
I have tried adding "gr-" + to the -alias and -displayname settings in the primary function, but it doesn't work:
function Import-UnixDL2Group {
[CmdletBinding()]
Param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
$InputObject
)
Process{
New-UnifiedGroup -Alias "gr-" + $InputObject.alias `
-DisplayName "gr-" + $InputObject.displayname `
-Members $InputObject.members.recipients.value `
-PrimarySmtpAddress $InputObject.emailaddresses.value `
}
}
I attempted to create a new function just for the purpose of prepending text:
function prependGR {
[CmdletBinding()]
Param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
$InputObject
)
Process {
"gr-" + $InputObject.alias
}
}
$allObjects | prependGR
The prependGR function produces the correct result, but it doesn't work with the main Import-UnixDL2Group function.
Adding another variable and calling the prependGR function in the process only produces gr- without the actual variables appended:
Process{
$renameAlias = $InputObject.alias | prependGR
New-UnifiedGroup -Alias $renameAlias `
I have been experimenting with adding additional parameters in the main function, but with no success.
Any guidance would be greatly appreciated.
Thank you in advance!