Cannot evaluate parameter 'Name' because its argument is specified as a script block

Hi Team.

I was hoping someone might be able to shine some light on an issue i am having with this script below.

What the script is doing is connecting to MS Teama and creating some Teams channels based on some data we have in a CSV file. The error message i am getting is below. Line 41 in the script starts

process {

The error message:

Get-Process : Cannot evaluate parameter ‘Name’ because its argument is specified as a script block and there is no input. A script block cannot be evaluated without
input.
At C:\Users\DummyAccountName\Desktop\Untitled1.ps1:41 char:13

  • process {
    
  •         ~
    
    • CategoryInfo : MetadataError: (:slight_smile: [Get-Process], ParameterBindingException
    • FullyQualifiedErrorId : ScriptBlockArgumentNoInput,Microsoft.PowerShell.Commands.GetProcessCommand
Connect-MicrosoftTeams
#

$time = Get-Date -Format "yyyy-MM-dd-HH-mm"
$logfile = "C:\temp\CreateTeams_task-$time.txt"
Start-Transcript -Path $logfile -Append

function Create-Channel ($ChannelName, $GroupId)
{   
        try {
            $teamchannels = $ChannelName -split ";" 
              if ($teamchannels) {
                for ($i = 0; $i -le ($teamchannels.count - 1) ; $i++) {
                    New-TeamChannel -GroupId $GroupId -DisplayName $teamchannels[$i]
                }
            }
        }
        Catch {
        }
    }

function Add-Users($Users, $GroupId, $CurrentUsername, $Role)
{     
        try {
            $teamusers = $Users -split ";" 
            if ($teamusers) {
                for ($j = 0; $j -le ($teamusers.count - 1) ; $j++) {
                    if ($teamusers[$j] -ne $CurrentUsername) {
                        Add-TeamUser -GroupId $GroupId -User $teamusers[$j] -Role $Role
                    }
                }
            }
        }
        catch {
        }
    }

function Create-NewTeam($ImportPath)
{   
   }
    process {
        Import-Module MicrosoftTeams
        
        $teams = Import-Csv -Path $ImportPath
        foreach ($team in $teams) {
            $getteam = get-team | Where-Object { $_.displayname -eq $team.'Team workspaces' }
            if ($getteam -eq $null) {
                Write-Host "Start creating the team: " $team.'Team workspaces'
                $group = New-Team -displayname $team.'Team workspaces' -Owner $team.'Owners 1' -MailNickName $team.MailNickName  -Visibility Private -AllowCreateUpdateChannels $false -AllowCreatePrivateChannels $false -AllowAddRemoveApps $false -AllowCreateUpdateRemoveTabs $false -AllowCreateUpdateRemoveConnectors $false -GiphyContentRating Strict -AllowDeleteChannels $false -AllowUserDeleteMessages $false -AllowOwnerDeleteMessages $false -AllowUserEditMessages $false
                Write-Host "Adding team Owners..."
                Add-Users -Users $team.Allowners -GroupId $group.GroupId -CurrentUsername $username  -Role owner 
                Write-Host "Adding team Members..." -ForegroundColor Yellow
                Add-Users -Users $team.Allmembers -GroupId $group.GroupId -CurrentUsername $username  -Role member 
                Write-Host "Completed creating the team: " $team.'Team workspaces'
                $team = $null
            }
            elseif($getteam -ne $null) {
            $teamname = $team.'Team workspaces'
            Write-Host "Team: $teamname exists " -ForegroundColor Black -BackgroundColor Magenta
            $teamname =$null
            }
        }
}

Create-NewTeam -ImportPath "C:\Teams\CreateBulkTeams.csv"

Stop-Transcript

This section was our original code and the script does work when used like below.

function Create-NewTeam {   
    param (   
        $ImportPath
    )   
    Process {

However i need to specify the $ImportPath like the example below. Or something similar. The reason being is the script will eventually be run in Quest Active Roles and that does not like the script with the above example.

function Create-NewTeam($ImportPath)
{   
   }
    process {

The syntax is wrong. You close the first curly brace immediately without any code in it!? :man_shrugging:t4: It should be …

function Create-NewTeam($ImportPath){   
    process {}
}

And it does not matter how you define your parameters. If it’s like this

function Create-NewTeam($ImportPath){   
    process {}
}

… or like this …

function Create-NewTeam {   
    param (   
        $ImportPath
    )   
    Process {}
}

… it works the same.

Thank you for explaining this to me. I get it now

many thanks

Craig