Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TeamsChannel: System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'GroupId' because it is null. #3943

Closed
skghq opened this issue Nov 23, 2023 · 12 comments · Fixed by #4107 or #4113

Comments

@skghq
Copy link

skghq commented Nov 23, 2023

Description of the issue

I will update to the latest version when I have a chance in a few days.

Command:
Export-M365DSCConfiguration -Components @("TeamsChannel") -Credential $Credential -Path $FilePath -FileName $FileName

Stack Trace:
[2023/11/23 09:30:53]
{InvalidData}
System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'GroupId' because it is null.
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
"Error during Export:"
at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1115.1\DSCResources\MSFT_TeamsChannel\MSFT_TeamsChannel.psm1: line 388
at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1115.1\modules\M365DSCReverse.psm1: line 615
at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1115.1\modules\M365DSCUtil.psm1: line 1320
at , C:\Scripts<<>>\Office365_Backup_Debug.ps1: line 5629
<<>>@<<>>.onmicrosoft.com
TenantId: <<>>.onmicrosoft.com

PS Output:
Transcript started, output file is C:\temp<<>>\debug\log\TeamsChannel.txt
Exporting Microsoft 365 configuration for Components: TeamsChannel
There is a newer version of the 'Microsoft365DSC' module available on the gallery.
To update the module and it's dependencies, run the following command:
Update-M365DSCModule

Authentication methods specified:

  • Credentials

Connecting to {MicrosoftTeams}...✅
[1/1] Extracting [TeamsChannel] using {Credentials}...

<<< a lot of output>>>

|---[678/1668] Team <<<Team 1>>>
    |---[1/1] <<<Name 1>>>✅
|---[679/1668] Team <<<Team 2>>>
    |---[1/2] <<<Name 1>>>✅
    |---[2/2] <<<Name 2>>>✅
|---[680/1668] Team <<<Team 3>>>
    |---[1/1] <<<Name 1>>>✅


Error Log created at {file://C:/temp/<<>>/debug/cwd/5112-M365DSC-ErrorLog.log}
⌛ Export took {2232 seconds}
Transcript stopped, output file is C:\temp<<>>\debug\log\TeamsChannel.txt

Microsoft 365 DSC Version

1.23.1115.1

Which workloads are affected

Teams

The DSC configuration

Export-M365DSCConfiguration -Components @("TeamsChannel") -Credential $Credential -Path $FilePath -FileName $FileName

Verbose logs showing the problem

Stack Trace:
[2023/11/23 09:30:53]
{InvalidData}
System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'GroupId' because it is null.
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
"Error during Export:"
at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1115.1\DSCResources\MSFT_TeamsChannel\MSFT_TeamsChannel.psm1: line 388
at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1115.1\modules\M365DSCReverse.psm1: line 615
at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1115.1\modules\M365DSCUtil.psm1: line 1320
at <ScriptBlock>, C:\Scripts\<<<redacted>>>\Office365_Backup_Debug.ps1: line 5629
<<<redacted>>>@<<<redacted>>>.onmicrosoft.com
TenantId: <<<redacted>>>.onmicrosoft.com

PS Output:
Transcript started, output file is C:\temp\<<<redacted>>>\debug\log\TeamsChannel.txt
Exporting Microsoft 365 configuration for Components: TeamsChannel
There is a newer version of the 'Microsoft365DSC' module available on the gallery.
To update the module and it's dependencies, run the following command:
Update-M365DSCModule
 
Authentication methods specified:
- Credentials
 
Connecting to {MicrosoftTeams}...✅
[1/1] Extracting [TeamsChannel] using {Credentials}...

<<< a lot of output>>>

    |---[678/1668] Team <<<Team 1>>>
        |---[1/1] <<<Name 1>>>✅
    |---[679/1668] Team <<<Team 2>>>
        |---[1/2] <<<Name 1>>>✅
        |---[2/2] <<<Name 2>>>✅
    |---[680/1668] Team <<<Team 3>>>
        |---[1/1] <<<Name 1>>>✅

 Error Log created at {file://C:/temp/<<<redacted>>>/debug/cwd/5112-M365DSC-ErrorLog.log}
⌛ Export took {2232 seconds}
Transcript stopped, output file is C:\temp\<<<redacted>>>\debug\log\TeamsChannel.txt

Environment Information + PowerShell Version

OsName               : Microsoft Windows Server 2019 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Key   : PSVersion
Value : 5.1.17763.4974
Name  : PSVersion

Key   : PSEdition
Value : Desktop
Name  : PSEdition

Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name  : PSCompatibleVersions

Key   : BuildVersion
Value : 10.0.17763.4974
Name  : BuildVersion

Key   : CLRVersion
Value : 4.0.30319.42000
Name  : CLRVersion

Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion

Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion

Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion
@skghq
Copy link
Author

skghq commented Nov 24, 2023

I have upgraded to 1.23.1122.1. This is still an issue.

I also re-ran it with the "-Verbose" parameter but no additional useful information was recorded.

VERBOSE: Dependencies were already successfully validated.
VERBOSE: Credential was specified. Connecting via User Principal
VERBOSE: Dependencies were already successfully validated.

PS>TerminatingError(Get-TeamChannel): "Cannot bind argument to parameter 'GroupId' because it is null."

Error Log created at {file://C:/temp/<<>>/Debug-Permissions2/cwd/5752-M365DSC-ErrorLog.log}
⌛ Export took {
1935 seconds
}

@malauter
Copy link
Member

@skghq Could you please check the output of Get-Team for any groups without a GroupId? Normally each group must have a valid Id, but your log says it is null for one of the groups and I cannot reproduce this in my environment.

@skghq
Copy link
Author

skghq commented Dec 27, 2023

@malauter Minimally redacted:

  • AR Team: Fails
  • Project Rebrand: Works
PS C:\temp\scott\debug\cwd> Get-Team -DisplayName "Project Rebrand"

GroupId                              DisplayName         Visibility  Archived  MailNickName       Description       
-------                              -----------         ----------  --------  ------------       -----------       
01b0b86b-3610-488c-adae-54763d6e33d9 Project Rebrand     Private     False     ProjectRebrand     Project Rebrand   



PS C:\temp\scott\debug\cwd> Get-Team -DisplayName "AR Team"

GroupId                              DisplayName         Visibility  Archived  MailNickName       Description       
-------                              -----------         ----------  --------  ------------       -----------       
791ba05f-4bd2-4953-8f30-3a80b07fe2b3 AR Team             Private     False     ARTeam33           We will place s...
b9f8cbde-0e83-4bcc-9b88-8c6cdde22009 <NAME 1> v. NNN...  Private     False     <NAME 1>.TeamP...  <NAME 1> v. NNN...
6811f029-0c77-4ea5-982b-b09138681a21 AR Team             Private     False     ARTeam             AR Team           
cc22a431-b91d-4ea1-9ac9-8afb26efe9ac <NAME 2> v YYY -... Private     False     <NAME 2>-XXX...    <NAME 2> v YYY -...

get-team.txt

@skghq
Copy link
Author

skghq commented Dec 27, 2023


PS C:\temp\scott\debug\cwd> Get-Team -DisplayName "AR Team" -Debug -Verbose
VERBOSE: Done performing authorization
VERBOSE: Executing Get-Team for parameters GroupId: , User: , Archived: , Visibility: , DisplayName: AR Team, MailNickName: 
DEBUG: Making an api call to the uri: https://graph.microsoft.com/beta/groups?$filter=resourceProvisioningOptions/Any(x:x eq 'Team')&$top=20&$count=true&$search="displayName:AR Team"
VERBOSE: Attempting to retrieve team from indexes [0 to 3]
DEBUG: Processed Batch number : 1
DEBUG: Returning 4 teams
DEBUG: Failed to fetch 0 teams
VERBOSE: Retrieving groups list

GroupId                              DisplayName         Visibility  Archived  MailNickName       Description       
-------                              -----------         ----------  --------  ------------       -----------       
791ba05f-4bd2-4953-8f30-3a80b07fe2b3 AR Team             Private     False     ARTeam33           We will place s...
b9f8cbde-0e83-4bcc-9b88-8c6cdde22009 <NAME 1> v. NNN...  Private     False     <NAME 1>.TeamP...  <NAME 1> v. NNN...
6811f029-0c77-4ea5-982b-b09138681a21 AR Team             Private     False     ARTeam             AR Team           
cc22a431-b91d-4ea1-9ac9-8afb26efe9ac <NAME 2> v YYY -... Private     False     <NAME 2>-XXX...    <NAME 2> v YYY -...

VERBOSE: Done retrieving groups, getting team properties
VERBOSE: Done processing Get-Team

@malauter
Copy link
Member

@skghq The display name 'AR Team' is not unique, but this should not be a problem, this is why we are using the group id. I do not know why the group id could not be found during the export for one of your teams.
Can you still reproduce the issue with the most current version of M365 DSC and dependencies?

@skghq
Copy link
Author

skghq commented Dec 27, 2023

@malauter It looks like I gave you bad information. Yes -- I just updated to the latest version and reproduced it. 'AR Team' actually exports fine. It is the next team that fails.

If I look at the produced error log (Error Log created at {file://C:/temp/scott/debug/cwd/876-M365DSC-ErrorLog.log}) the last team is 'AR Team'.

Looking at the console window the last team activity is for 'Evaluation Committee'

Upgrade:

Update-Module Microsoft365DSC
Update-M365DSCDependencies
Uninstall-M365DSCOutdatedDependencies

Get-InstalledModule Microsoft365DSC | Select Version,InstalledLocation

Version     InstalledLocation                                                     
-------     -----------------                                                     
1.23.1220.1 C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1220.1

Console Output:

    |---[699/1696] Team {AR Team}
        |---[1/1] GeneralVERBOSE: Attempting connection to {MicrosoftTeams} with:
VERBOSE: 
Name                           Value                                                                                                                                                                                                                                           
----                           -----                                                                                                                                                                                                                                           
TenantId                                                                                                                                                                                                                                                                       
DisplayName                    General                                                                                                                                                                                                                                         
GroupID                        6811f029-0c77-4ea5-982b-b09138681a21                                                                                                                                                                                                            
TeamName                       AR Team                                                                                                                                                                                                                                         
Credential                     System.Management.Automation.PSCredential                                                                                                                                                                                                       
ApplicationId                                                                                                                                                                                                                                                                  
CertificateThumbprint                                                                                                                                                                                                                                                          



VERBOSE: Dependencies were already successfully validated.
VERBOSE: Credential was specified. Connecting via User Principal
VERBOSE: Dependencies were already successfully validated.
✅
    |---[700/1696] Team {Evaluation Committee}
        |---[1/4] 2022 Evaluation CommitteeVERBOSE: Attempting connection to {MicrosoftTeams} with:
VERBOSE: 
Name                           Value                                                                                                                                                                                                                                           
----                           -----                                                                                                                                                                                                                                           
TenantId                                                                                                                                                                                                                                                                       
DisplayName                    2022 Evaluation Committee                                                                                                                                                                                                                       
GroupID                        6967ff87-993c-42b1-ab87-679e038cd171                                                                                                                                                                                                            
TeamName                       Evaluation Committee                                                                                                                                                                                                                            
Credential                     System.Management.Automation.PSCredential                                                                                                                                                                                                       
ApplicationId                                                                                                                                                                                                                                                                  
CertificateThumbprint                                                                                                                                                                                                                                                          



VERBOSE: Dependencies were already successfully validated.
VERBOSE: Credential was specified. Connecting via User Principal
VERBOSE: Dependencies were already successfully validated.
✅
        |---[2/4] AdminVERBOSE: Attempting connection to {MicrosoftTeams} with:
VERBOSE: 
Name                           Value                                                                                                                                                                                                                                           
----                           -----                                                                                                                                                                                                                                           
TenantId                                                                                                                                                                                                                                                                       
DisplayName                    Admin                                                                                                                                                                                                                                           
GroupID                        6967ff87-993c-42b1-ab87-679e038cd171                                                                                                                                                                                                            
TeamName                       Evaluation Committee                                                                                                                                                                                                                            
Credential                     System.Management.Automation.PSCredential                                                                                                                                                                                                       
ApplicationId                                                                                                                                                                                                                                                                  
CertificateThumbprint                                                                                                                                                                                                                                                          



VERBOSE: Dependencies were already successfully validated.
VERBOSE: Credential was specified. Connecting via User Principal
VERBOSE: Dependencies were already successfully validated.
✅
        |---[3/4] 2023VERBOSE: Attempting connection to {MicrosoftTeams} with:
VERBOSE: 
Name                           Value                                                                                                                                                                                                                                           
----                           -----                                                                                                                                                                                                                                           
TenantId                                                                                                                                                                                                                                                                       
DisplayName                    2023                                                                                                                                                                                                                                            
GroupID                        6967ff87-993c-42b1-ab87-679e038cd171                                                                                                                                                                                                            
TeamName                       Evaluation Committee                                                                                                                                                                                                                            
Credential                     System.Management.Automation.PSCredential                                                                                                                                                                                                       
ApplicationId                                                                                                                                                                                                                                                                  
CertificateThumbprint                                                                                                                                                                                                                                                          



VERBOSE: Dependencies were already successfully validated.
VERBOSE: Credential was specified. Connecting via User Principal
VERBOSE: Dependencies were already successfully validated.
✅
        |---[4/4] GeneralVERBOSE: Attempting connection to {MicrosoftTeams} with:
VERBOSE: 
Name                           Value                                                                                                                                                                                                                                           
----                           -----                                                                                                                                                                                                                                           
TenantId                                                                                                                                                                                                                                                                       
DisplayName                    General                                                                                                                                                                                                                                         
GroupID                        6967ff87-993c-42b1-ab87-679e038cd171                                                                                                                                                                                                            
TeamName                       Evaluation Committee                                                                                                                                                                                                                            
Credential                     System.Management.Automation.PSCredential                                                                                                                                                                                                       
ApplicationId                                                                                                                                                                                                                                                                  
CertificateThumbprint                                                                                                                                                                                                                                                          



VERBOSE: Dependencies were already successfully validated.
VERBOSE: Credential was specified. Connecting via User Principal
VERBOSE: Dependencies were already successfully validated.
✅
❌
 Error Log created at {file://C:/temp/scott/debug/cwd/876-M365DSC-ErrorLog.log}
⌛ Export took {2173 seconds}
Transcript stopped, output file is C:\temp\scott\debug\log\TeamsChannel2.txt

Get-Team:

PS C:\temp\scott\debug\cwd> Get-Team -DisplayName "Evaluation Committee"

GroupId                              DisplayName        Visibility  Archived  MailNickName       Description       
-------                              -----------        ----------  --------  ------------       -----------       
6967ff87-993c-42b1-ab87-679e038cd171 Evaluation Comm... Private     False     EvaluationCommi... Manage tasks, s...

Get-TeamChannel for 'Evaluation Committee' (NOT WORKING):

PS C:\temp\scott\debug\cwd> Get-TeamChannel -GroupId 6967ff87-993c-42b1-ab87-679e038cd171

Id                                                           DisplayName               Description                                                                                                                                 MembershipType
--                                                           -----------               -----------                                                                                                                                 --------------
19:1c0b879e0a3c4463b86cc3ce563641b4@thread.tacv2             2022 Evaluation Committee                                                                                                                                                   Standard
19:81a39ce41bd84bdf823f87614b77ab5b@thread.tacv2             Admin                                                                                                                                                                        Private
19:e42a1c545f894029a17bda1eb59e981a@thread.tacv2             2023                                                                                                                                                                        Standard
19:I48qlnbQ8VbX8LSZuiooZiceUdJ92ujRtDTYS6i7IYE1@thread.tacv2 General                   Manage tasks, share documents, conduct project meetings and document risks and decisions with this template for general project management.       Standard

Get-TeamChannel for 'AR Team' (WORKING):

PS C:\temp\scott\debug\cwd> Get-TeamChannel -GroupId 6811f029-0c77-4ea5-982b-b09138681a21

Id                                               DisplayName Description MembershipType
--                                               ----------- ----------- --------------
19:c71b086258584f28987e4fb3df819c3e@thread.tacv2 General     AR Team           Standard

@skghq
Copy link
Author

skghq commented Dec 27, 2023

@malauter The "Membership Type" of private seems to stand out to me in the Get-TeamChannel output.

@malauter
Copy link
Member

@skghq Thanks for all the information. I have just created the same Team structure, even with a private channel, but still I cannot reproduce the issue.
Is this the only team/channel in your tenant causing the issue? The error says, that the group id of the team (not of the channel) is null, but if you run the cmdlet manually, the id is not null.

@skghq
Copy link
Author

skghq commented Dec 28, 2023

@malauter The script stops execution after the error so i'm not sure if that is the only team. I'll give debugging the script a go and let you know what I find. Any input on approaching this would be helpful.

@skghq
Copy link
Author

skghq commented Dec 28, 2023

@malauter I found the problem. Bad information again. Using the stack trace of the error i modified your code.

Stack trace:

[2023/12/27 09:59:45]
{InvalidData}
System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'GroupId' because it is null.
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
"Error during Export:"
at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1220.1\DSCResources\MSFT_TeamsChannel\MSFT_TeamsChannel.psm1: line 388
at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1220.1\modules\M365DSCReverse.psm1: line 639
at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1220.1\modules\M365DSCUtil.psm1: line 1312
at <ScriptBlock>, C:\Scripts\Scott\From-VW19ADMINSRV\GitHub-3943.ps1: line 27

I insert a line at 383 of MSFT_TeamsChannel.psm1:

    try
    {
        $teams = Get-Team -ErrorAction Stop
        $teams | Export-Csv -NoTypeInformation -delimiter "`t" C:\ETL\Production\365dsc_debug.txt # DEBUG CODE
        $j = 1
        $dscContent = ''
        Write-Host "`r`n" -NoNewline

I then imported the results of that to SQL:

/*
SELECT *
INTO DataPond_Staging.._DEBUG_365
FROM OPENROWSET(
    'Microsoft.ACE.OLEDB.16.0', 
    'Text; HDR=YES; Database=C:\ETL\Production\', 
    'SELECT * FROM 365dsc_debug.txt')
*/
select *
from DataPond_Staging.._DEBUG_365

'AR Team' and 'Evaluation Committee' are not at fault. See attached screenshot. I'm not sure how to go about providing you more information on this:
365dsc_results

@malauter
Copy link
Member

malauter commented Jan 2, 2024

I have no idea why there is this "NULL team" in your tenant. I think the only thing we can do is to adjust the code to skip the team if the GroupId is null.
@NikCharlebois What do you think?

@malauter
Copy link
Member

malauter commented Jan 2, 2024

@skghq Could you please test if the adjusted code from the PR linked above solves your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants