Help with pipeline basics / fundamentals ...

Hi … I don’t use PS that often and am struggling to understand why something won’t work.

This code works fine and does what I want, but I’d been trying to pipe the output of Get-ADGroup straight to Set-ADGroup without using the ForEach element.

Get-ADGroup -Identity "CN=TEST READ,OU=SEC,OU=BG Groups,DC=bg,DC=net" | ForEach-Object { $_ | Set-ADGroup -SamAccountName ($_.SamAccountName -Replace "TEST", "LIVE") -Verbose }
What I was originally was trying is below, but it errors. I'm guessing I'm not understanding something fundamental here about how PS works. Any help to understand what I'm doing wrong would be appreciated.
Get-ADGroup -Identity "CN=TEST READ,OU=SEC,OU=BG Groups,DC=bg,DC=net" | Set-ADGroup -SamAccountName ($_.SamAccountName -Replace "TEST", "LIVE") -Verbose
Thanks

The -SamAccountName parameter of Set-ADGroup doesn’t take pipeline input. You can only use “$_” inside script blocks, “{ }”.

-SamAccountName
Specifies the Security Account Manager (SAM) account name of the user, group, computer, or service account. The maximum length of the description is 256 characters. To be compatible with older operating systems, create a SAM account name that is 20 characters or less. This parameter sets the SAMAccountName for an account object. The LDAP display name (ldapDisplayName) for this property is sAMAccountName.

Note: If the string value provided is not terminated with a $ (dollar sign) character, the system adds one if necessary.

Type:	String
Position:	Named
Default value:	None
Accept pipeline input:	False
Accept wildcard characters:	False

Didn’t test, you try delay binding.

Get-ADGroup -Identity "CN=TEST READ,OU=SEC,OU=BG Groups,DC=bg,DC=net" | Set-ADGroup -SamAccountName {$_.SamAccountName -Replace "TEST", "LIVE"} -Verbose

Delay binding only works when the parameter can take pipeline input. I didn’t know it had a name!

yup, you are right. Thanks @js2010