Is it possible to create a Microsoft team from a template with Powershell? - powershell

I am currently writing a Powershell script to create teams in Microsoft Teams.
Is there a way to use a template when creating a team in Powershell?
Thanks in advance.

Yes, it is possible, but not with the MicrosoftTeamsPowerShell module's New-Team. As per the docs, the -Template parameter is for Education customers:
If you have an EDU license, you can use this parameter to specify which template you'd like to use for creating your group. Do not use this parameter when converting an existing group.
Valid values are: "EDU_Class" or "EDU_PLC"
Instead, you can do this using Microsoft Graph, in particular the Create Team operation. One of the examples listed in the docs describes how to use the AdditionalProperties to specify a template, and once you know it's possible in Graph in concept, it's simply a case of finding the matching operation in the Microsoft Graph PowerShell module, in this case New-MgTeam (more info here).
For some final code, you can use the following:
Connect-MgGraph -Scopes "Team.Create"
$additionalProperties = #{
"template#odata.bind" = "https://graph.microsoft.com/v1.0/teamsTemplates('com.microsoft.teams.template.ManageAProject')"
}
New-MgTeam -DisplayName "SOTest" -AdditionalProperties $additionalProperties
This example using the Project Team template - here is a list of the out of box templates. For your custom templates, you can create them in the admin centre or via PowerShell, and you can read more about them here. To actually use a custom template, you use it's Guid in the form of:
$additionalProperties = #{
"template#odata.bind" = "https://graph.microsoft.com/v1.0/teamsTemplates('[your guid here]')"
}
Just a final note to be aware of - the PowerShell command executes quite quickly, and it creates the initial team pretty fast too, but it takes a few minutes to apply the template thereafter (e.g. creating the channels etc.) - give it 5 - 10 minutes and it should be fine.

Related

VSTS: Built in variable for organization name?

In many of the calls described in the Azure DevOps REST API documentation, I need to supply the name of the organization, e.g.:
https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=5.0-preview.8
The project I can get from System.TeamProject. I would have expected something similar for organization name, something like:
System.TeamFoundationCollectionName
This does not seem to be available. I've even printed out all of my environment variables on the agent and don't see anything that fits the need exactly. Sure, I can parse it out of one of the other values, but this seems fragile since MS seems to like to change the format of URLs.
I also can't hard code the organization name because this release definition will live in multiple organizations and we don't want to have to manually update it for each. How are others solving this problem?
Try using System.TeamFoundationServerUri and System.TeamFoundationCollectionUri to build your API requests. They have the organization included in them.
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=vsts&tabs=batch
edit: SYSTEM_TEAMFOUNDATIONSERVERURI/BUILD_PROJECTNAME/_apis/release/releases?api-version=5.0-preview.8
It looks like currently there is no such variable for the organization, also, the variables return the old URL (xxx.visualstudio.com) and not the new URL (dev.azure.com/xxx) so if you use the System.TeamFoundationCollectionName the API should work without the {organization}:
https://System.TeamFoundationCollectionName/{project}/_apis/release/releases?api-version=5.0-preview.8.
In Powershell, do this:
# Where SYSTEM_TEAMFOUNDATIONCOLLECTIONURI=https://some_org_name.visualstudio.com/
([System.Uri]$Env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI).Host.split('.')[-3] # returns 'some_org_name'
Now, just assign that to a variable and use it anywhere you like. "SYSTEM_TEAMPROJECT" is the Project Name, so no need to do any parsing there. It is already available.

Export the Type from an Azure Resource Group using PowerShell

I am trying to export the Type field from Azure using PowerShell.
UsingFind-AzureRMResource I get a lot of info, but I would like to have the type description as seen in the portal when viewing resources in a resource group:
Is it possible to get this info from Azure using PowerShell?
TYPE on Azure Portal equals ResourceType on PowerShell cmdlet. For example, Network security group equals Microsoft.Network/networkSecurityGroups. If you want to get it as TYPE on Portal, you could use hash map. For example.
$hash = #{}
$hash['Microsoft.Network/networkSecurityGroups'] = "Network security group"
$result=Find-AzureRMResource -ResourceType "Microsoft.Network/networkSecurityGroups"
$test=$result.ResourceType[0]
echo $hash[$test]
Please refer to my answer.
Thanks for RalJans share. Use a name convention with an abbrivation of the Type so I build a switch to get the correct name. Please refer to this link.
I don't think this information is exposed anywhere, but you can create a hash table to map those values and format output with that.

Can I enable / Disable an Azure Service Bus Topic using Powershell

I have spent a couple of hours search for a solution to disable my Azure Service Bus Topics using Powershell.
The background for this is we want to force a manual failover to our other region.
Obviously I could click in the Portal:
but I want to have a script to do this.
Here is my current attempt:
Any help would be great.
Assuming you're sure your $topic contains the full description, modify the status parameter in the array and then splat it back using the UpdateTopic method. I'm afraid I can't test this at present.
$topic.Status = "Disabled"
$topicdesc = $NamespaceManager.UpdateTopic($topic)
I don't think you'll need to set the entity type for the Status, nor do you require semi-colons after each line of code in your loop.
References
PowerShell Service Bus creation sample script (which this appears to be based off): https://blogs.msdn.microsoft.com/paolos/2014/12/02/how-to-create-service-bus-queues-topics-and-subscriptions-using-a-powershell-script/
UpdateTopic method: https://msdn.microsoft.com/en-us/library/azure/microsoft.servicebus.namespacemanager.updatetopic.aspx
Additional note: please don't screenshot the code - paste it in. I'd rather copy-and-paste than type things out.

vmware powercli

i want to create New vm's from muliple template's like windows 8,7 and more like that, also want to choose how many i need of that vm.
the full code is here:
link to pastebin
but the thing is i want to do multiple templates at once how can i do that?
i was thinking about an foreach($template in $template){do that}
then im doing template1,template2 but its giving me the error that its just template1,template2 instead of 2 diffrent templates dont know how to seperate that. i thought about the , but i dont know then.
This is not possible, you have to specify one (and only one) template to create a new from template.
You can verify that by running the following command :
Get-Help New-VM -Parameter Template
-Template <Template>
Specifies the virtual machine template you want to use for the creation of the new virtual machine. Passing values to this parameter through a pipeline is deprecated and will be disabled in a future release.
Required? true
Position? 2
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? true
As you can see , this -Template parameter takes only one object of the type [Template].
If it were able to take several, we would see :
-Template <Template[]>
But it is the same in the GUI anyway : in the vSphere client you have to choose only one template to create a VM from it.

Create a particular type of link between two WorkItem's in TFS using PowerShell

I am creating test cases (Test Case type of task) in PowerShell and I am trying to link them to a story (Product Backlog Item) as "Test Cases" and not as ordinary links.
Suppose $WIT is the WorkItemStore and $testcaseId and $storyId are valid IDs.
If I do:
$testCase = $WIT.GetWorkItem($testcaseId)
$workitem.Links.Add($storyId)
$workitem.Save()
I will have a bunch of "normal" links from the test case to the story, which is not what I want.
In C#, this seems to be achievable by creating a new RelatedLink and specifying the type of the link. Here's a snippet (more info here)
source.Links.Add(new RelatedLink(linkTypeEnd, approval.Id));
Is there any way to do the same in PowerShell?
You can do it in Powershell the same way that you do it in C#... that's the awesome power of PowerShell :)
[Microsoft.TeamFoundation.WorkItemTracking.Client.Hyperlink]$NewLink = New-Object -TypeName Microsoft.TeamFoundation.WorkItemTracking.Client.Hyperlink -ArgumentList $newlocation
$wit.Links.Add($NewLink)
I first use the PowerShell function above to pull in the relevant DLL's then I have access to the Above is the code to create and add a new Hyperlink. From this you should be able to easily create other types of links.