Uber22 Posted April 22, 2020 Posted April 22, 2020 Hi All i have been trying to connect to Teams Powershell with no luck, i have submitted a ticket to my csp but they havent been able to help me connect i have put the error i am seeing below. can anyone help🙌 PS C:\Windows\system32> #$Credential = Get-Credential Connect-AzureAD -Credential $Credential Import-Module MicrosoftTeams Connect-MicrosoftTeams -Credential $Credential $Group = Get-AzureADGroup -All $true | Where-Object {$_.DisplayName -eq "Students" } #needs to be in "" change this to your Azure group name $Members = Get-AzureADGroupMember -ObjectId $Group.ObjectId -All $true foreach ($Member in $Members) { Grant-CsUserPolicyPackage -Identity $Member.UserPrincipalName -PackageName "Education_SecondaryStudent" # Change this to Education_Teacher for your staff if you want to. } Connect-AzureAD : The term 'Connect-AzureAD' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:3 char:1 + Connect-AzureAD -Credential $Credential + ~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Connect-AzureAD:String) [], Com mandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Connect-MicrosoftTeams : The term 'Connect-MicrosoftTeams' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:7 char:1 + Connect-MicrosoftTeams -Credential $Credential + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Connect-MicrosoftTeams:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Get-AzureADGroup : The term 'Get-AzureADGroup' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:9 char:10 + $Group = Get-AzureADGroup -All $true | Where-Object {$_.DisplayName - ... + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-AzureADGroup:String) [], Co mmandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Get-AzureADGroupMember : The term 'Get-AzureADGroupMember' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:11 char:12 + $Members = Get-AzureADGroupMember -ObjectId $Group.ObjectId -All $tru ... + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-AzureADGroupMember:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
mavhc Posted April 22, 2020 Posted April 22, 2020 You need to manually install the modules, it's very annoying
mdrabble Posted April 22, 2020 Posted April 22, 2020 @Uber22 Before running the powershell script type in the following install-module MicrosoftTeams
Uber22 Posted April 22, 2020 Author Posted April 22, 2020 PS C:\Windows\system32> install-module MicrosoftTeamsPS C:\Windows\system32> Import-Module MicrosoftTeamsPS C:\Windows\system32> Connect-MicrosoftTeams -Credential $CredentialConnect-MicrosoftTeams : The term 'Connect-MicrosoftTeams' is not recognizedas the name of a cmdlet, function, script file, or operable program. Checkthe spelling of the name, or if a path was included, verify that the path iscorrect and try again.At line:1 char:1+ Connect-MicrosoftTeams -Credential $Credential+ ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Connect-MicrosoftTeams:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
mdrabble Posted April 22, 2020 Posted April 22, 2020 I prefer to use Powershell ISE as you can run lines of code at a time - aso you need to make sure you are right click and run as admin install-module MicrosoftTeams -Force -Verbose Also worth checking and trying the following Get-PSRepository and you should see something silimar - Name InstallationPolicy SourceLocation ---- ------------------ -------------- PSGallery Untrusted https://www.powershellgallery.com/api/v2
Uber22 Posted April 22, 2020 Author Posted April 22, 2020 VERBOSE: Using the provider 'PowerShellGet' for searching packages.VERBOSE: The -Repository parameter was not specified. PowerShellGet will use all of the registered repositories.VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='MicrosoftTeams'' for ''.VERBOSE: Total package yield:'1' for the specified package 'MicrosoftTeams'.VERBOSE: Performing the operation "Install-Module" on target "Version '1.0.6' of module 'MicrosoftTeams'".VERBOSE: The installation scope is specified to be 'AllUsers'.VERBOSE: The specified module will be installed in 'C:\Program Files\WindowsPowerShell\Modules'.VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.VERBOSE: Downloading module 'MicrosoftTeams' with version '1.0.6' from the repository'https://www.powershellgallery.com/api/v2'.VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='MicrosoftTeams'' for ''.VERBOSE: InstallPackage' - name='MicrosoftTeams',version='1.0.6',destination='C:\Users\adm\AppData\Local\Temp\62669380'VERBOSE: DownloadPackage' - name='MicrosoftTeams',version='1.0.6',destination='C:\Users\adm\AppData\Local\Temp\62669380\MicrosoftTeams\MicrosoftTeams.nupkg',uri='https://www.powershellgallery.com/api/v2/package/MicrosoftTeams/1.0.6'VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/MicrosoftTeams/1.0.6'.VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/MicrosoftTeams/1.0.6'.VERBOSE: Completed downloading 'MicrosoftTeams'.VERBOSE: Hash for package 'MicrosoftTeams' does not match hash provided from the server.VERBOSE: InstallPackageLocal' - name='MicrosoftTeams',version='1.0.6',destination='C:\Users\adm\AppData\Local\Temp\62669380'VERBOSE: Catalog file 'MicrosoftTeams.cat' is not found in the contents of the module 'MicrosoftTeams' being installed.VERBOSE: Valid authenticode signature found in the file 'MicrosoftTeams.psd1' for the module 'MicrosoftTeams'.VERBOSE: For publisher validation, current module 'MicrosoftTeams' with version '1.0.6' with publisher name'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'. Is this modulesigned by Microsoft: 'True'.VERBOSE: For publisher validation, using the previously-installed module 'MicrosoftTeams' with version '1.0.6' under'C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\1.0.6' with publisher name 'CN=Microsoft Root CertificateAuthority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'. Is this module signed by Microsoft: 'True'.VERBOSE: Authenticode issuer 'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond,S=Washington, C=US' of the new module 'MicrosoftTeams' with version '1.0.6' matches with the authenticode issuer'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' of thepreviously-installed module 'MicrosoftTeams' with version '1.0.6'.WARNING: The version '1.0.6' of module 'MicrosoftTeams' is currently in use. Retry the operation after closing theapplications.
mdrabble Posted April 22, 2020 Posted April 22, 2020 (edited) wondering if there is an issue with your powershell, as when I run that command on WIn10 and Server 2016 and 2019 it installs fine. I'll copy the module and upload it with instructions on how to manually install the module in the morning if that ok. Edited April 22, 2020 by mdrabble
mdrabble Posted April 22, 2020 Posted April 22, 2020 Just read the last bit of the message you posted and it looks like the module is installed as it says the module is in use. Will take a proper look in the morning as my little one has just woken up and needs feeding.
mdrabble Posted April 23, 2020 Posted April 23, 2020 Let’s start from scratch and close any and all powershell windows. Open either powershell or powershell ise as admin Don’t run any scripts just yet and run the following command Get-InstalledModule Should return a list of all installed modules and hopefully we should see MicrosoftTeams If MicrosoftTeams is listed then on another new line type in Import-Module MicrosoftTeams -verbose Using the -verbose switch so we can see what is happening when the command runs. Hopefully you shouldn’t see any error messages. If at this point all is good, then you should be able to run the powershell script to assign the team assignments.
Katy Posted April 23, 2020 Posted April 23, 2020 Have you installed the AzureAD module (as it's failing on the Get-AzureADGroup cmdlets)? Install-Module AzureAD in an elevated shell, then in the script Import-Module AzureAD
Cache Posted April 23, 2020 Posted April 23, 2020 Just had the same thing on a different server - paste this into your powershell window before you do install-module so that it uses TLS1.2: [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Source: https://www.codyhosterman.com/2016/06/force-the-invoke-restmethod-powershell-cmdlet-to-use-tls-1-2/
Uber22 Posted April 23, 2020 Author Posted April 23, 2020 Hi All Thanks for you help, i have managed to get the powershell working, but the script to set the permission for the students doesnt seem to work ? Has anyone applied permissions via Powershell to a group such as "Students" Thanks
mdrabble Posted April 23, 2020 Posted April 23, 2020 (edited) On the script it looks for an AD group called students as that’s what I have my students in - made it easier to apply on mass. I created an AD group called students and added all student accounts to that group that way the script could apply setting to all Students in one go. If your students are in a different AD group change students in the script to match your AD group. Hope that makes sense. Edited April 23, 2020 by mdrabble
HPlum78 Posted April 23, 2020 Posted April 23, 2020 Personally I would use a group like @mdrabble has said or set an ext attrib on the accounts as you provision them from your identity management system then you can ripple a get-Aduser over AD. Loading out of a file adds a step thats not required and makes it difficult to run any kind of script that checks local users against synced users. That's said those type of scripts come over time.
mdrabble Posted April 23, 2020 Posted April 23, 2020 I’ll post my original script later this evening. Don’t remember setting that variable.
HPlum78 Posted April 23, 2020 Posted April 23, 2020 The reason I ask is a get-content is streaming in a file (I am assuming that the file contains a list of users?) then the next line uses that var in -Identity apart from the fact PS is saying don't pass me a Null value even if it ain't null that's going to throw an exception. Would need to use some kind of loop...
HPlum78 Posted April 23, 2020 Posted April 23, 2020 $user_ids.foreach({PS COMMAND -Identity $_ -OTHERPARAMS}) The foreach method is by far the best way to invoke looping in PS since PS V4 due to the work that the .NET team have done under the hood.
mdrabble Posted April 24, 2020 Posted April 24, 2020 @Uber22 - Here is my original script $cred = Get-Credential "[email protected]" Connect-AzureAD -Credential $cred Connect-MicrosoftTeams -Credential $cred #Change Students in Year 7 to your selected AD Group $group = Get-AzureADGroup -SearchString "Students in Year 7" $members = Get-AzureADGroupMember -ObjectId $group.ObjectId -All $true | Where-Object {$_.ObjectType -eq "User"} #Name : Education_Teacher #Description : This is an Education_Teacher package # #Name : Education_SecondaryStudent #Description : This is an Education_SecondaryStudent package #Change the PackageName to your chosen package $members | ForEach-Object { Write-host Assigning Team Policy to: $_.UserPrincipalName Grant-CsUserPolicyPackage -PackageName Education_SecondaryStudent -Identity $_.UserPrincipalName } [/Code] One thing I forgot to mention is that we use AzureConnect - so when we create AD Groups etc, they then get Sync'd into Azure. I use groups for my students - such as Students in Year 7 for all students in Year 7, etc..... So providing your students are in a group, all you need to do is change $group to match your chosen AD Group. Hope that all makes sense....... If anyone can see if there is an easier way to do the loops than by all means let me know :-)
mavhc Posted April 25, 2020 Posted April 25, 2020 also doesn't work properly if you've actually set up 2fa, sigh
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now