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: (
[Get-Process], ParameterBindingException - FullyQualifiedErrorId : ScriptBlockArgumentNoInput,Microsoft.PowerShell.Commands.GetProcessCommand
- CategoryInfo : MetadataError: (
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