none
How can I replace a String param with one that has the value or a collection of strings

    Question

  •  Param (
            [Parameter(Mandatory=$true,
                       ValueFromPipeline = $True,
                       ValueFromPipelineByPropertyName=$true)]
           [string[]]$GroupName
            ) #pararmeter

    I want to replace the:

    [String[]]$GroupName

    With:

    $GroupName = Get-ADGroup -Filter {name -like "acl*full"} | Select-Object -ExpandProperty name

    when I tried to replace I get errors. Please help.

    Thanks much in advance


    POWERSHELL

    Friday, May 24, 2019 6:28 PM

All replies

  • function Get-FullGroupMember {
       
        [CmdletBinding()]
        [Alias()]
        [OutputType([int])]
        Param (
            [Parameter(Mandatory=$true,
                       ValueFromPipeline = $True,
                       ValueFromPipelineByPropertyName=$true)]

            [string[]]$GroupName    ----How can I replace this  parameter with this one bellow instead?

                                          $GroupName = Get-ADGroup -Filter {name -like "acl*full"} | Select-Object -ExpandProperty name

            ) #pararmeter
       
        begin {
            $grouparray = [system.collections.arraylist]@()

            foreach ($group in $groupname){
                $groupobj = [pscustomobject]@{
                    Name = $group
                    NestedIn = $null
                } #groupobj

                $grouparray.Add($groupobj) | Out-Null
            }
           
            $groupuser = @()
            $outdata = [System.Collections.ArrayList]@()

        } #begin

        process {
       
            do {
                $groupmember = Get-ADGroupMember $grouparray[0].Name

                foreach ($subgroup in $groupmember | Where-Object objectclass -eq "group"){
           
                    $groupobj = [pscustomobject]@{
                        Name = $subgroup.name
                        NestedIn = $grouparray[0].Name
                    } #groupobj

                    $grouparray.Add($groupobj) | Out-Null
           
                } #foreach subgroup
       
                $groupuser = $groupmember | Where-Object objectclass -eq "user"
       
                foreach ($user in $groupuser) {
                    if ($user.distinguishedName -like "*dc=dss*"){
                        $aduser = Get-ADUser $user.SamAccountName -Properties emailaddress, canonicalname -Server dcf-inf-bos-081.dss.govt.state.ma.us
                    } #if DSS
                    else {
                        $aduser = Get-ADUser $user.SamAccountName -Properties emailaddress, canonicalname
                    } #else


                    $obj = [pscustomobject]@{
                        GroupName = $grouparray[0].Name
                        NestedIn = $grouparray[0].NestedIn
                        SAMAccountName = $user.SAMAccountName
                        Name = $aduser.name
                        CanonicalName = $aduser.canonicalname
                        Emailaddress = $aduser.emailaddress

                    } #obj
                $outdata.Add($obj) | Out-Null
                } #foreach user

                $grouparray.Removeat(0)
       
            } while ($grouparray -ne $Null)

            #$outdata | Export-Csv -Path c:\temp\Group_Audit.csv -NoTypeInformation   

        } #process
        end {
            return $outdata
        } #end


    POWERSHELL

    Friday, May 24, 2019 6:09 PM
  • You should contact the author of the script to ask for support or a change.

    Regardless of that: Please format your code as code using the code posting tool provided on the icon bar of the post editor (second to last icon). Thanks  (do not create a new post - edit the one above you already created)


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, May 24, 2019 6:24 PM
  • Just pass the list to the function.  That is why that is a parameter.


    \_(ツ)_/

    Friday, May 24, 2019 6:29 PM