Create a particular type of link between two WorkItem's in TFS using PowerShell - 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.

Related

Is it possible to create a Microsoft team from a template with 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.

Handle a COM event in PowerShell

I am controlling an application via its COM server from PowerShell. This is pretty simple:
# Start the application via COM
$app = New-Object -ComObject CoolApp.Application
# Start a data measurement in the application
$measurement = $app.Measurement
$measurement.Start()
Now comes the hard part: the Measurement object has an event called "OnFinished", that is invoked when the data measurement is done. I would like my powershell script to wait for the occurence of this event.
How can I subscribe to such an COM event PowerShell?
If a Primary Interop Assemblies(PIA) is provided from the developer to the COM object you are using, you can easily register event handlers by using it.
For example, refer to this description.
Registering and Catching Communicator 2007 Automation API Events
Like the above components and Office, PIA is provided for many of Microsoft's products.
Office primary interop assemblies
If there is no PIA, you can request it from the developer or you can create it yourself.
The way to make it is explained on this page.
How to: Generate Primary Interop Assemblies Using Tlbimp.exe
Is OnFinished a property of the app or measure object? If it is, and it returns a value when queried you could use a while loop to wait for that returned value to be a specific value e.g. if that property returns 'Completed' once the process has finished:
while($measure.OnFinished -ne 'Completed')
{
Sleep 5
}
Difficult to be more specific with my answer as I am not familiar with your COM object :)

Simulating a Mouse Click in Powershell

I already know Powershell is not really meant for GUI automation, but just the same I have a pretty large Powershell script that needs to perform a single GUI operation, that being a left mouse click. I have searched for hours and have not found a satisfactory solution. The closest I have found is an add on called Wasp, but it was written in 2009 and appears to be incomplete anyway.
Is there another add in available to solve this problem?
I cannot condone using this as a first resort, but it should work. Generally when dealing with web pages you want to use URL parameters as much as possible since webpage elements are volatile.
With that said you should be able to create an IE comobject and then select the element that way. For example:
First create an IE object:
$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.navigate("YourPageURLHere.com")
$ie.visible = $true
You can manipulate certain elements by ID (ex: name="username") or even type. These can be easily found be viewing the source code of a webpage. Here are a few examples:
$Username = $ie.document.getElementByID("Username")
$Username.value = $UsernameValue
$SearchButton = $ie.Document.getElementsByTagName("button")
$SearchButton.click()
Even if the webpage changes, since we have it all attached to the IE object you can then grab the output elements that generate after the submit button is clicked and feed them back into your script.

How can i add endnotes to a word doc using Powershell?

Hello I'm looking for a way to search for a word in a word doc and add an endnote(special type of footnote) with a definition of the word as the endnote text. This would allow me to hover over that word and then the definition would pop up like a tool tip.
I know i need to use reflection, but i'm new to the whole reflection thing and all my attempts have fallen flat.
I've found the reference for endnotes here: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.endnotes.add%28office.11%29.aspx
I've tried loading C:\WINDOWS\Assembly\Gac\Microsoft.Office.Interop.Word\11.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll using reflection, but i don't know what to do once i've loaded it. When i try to create an new-object, it still asks me if i've loaded the appropriate dll.
Additionally i tried to fix the problem with a diff method by loading the MS word application as a comobject, but i wasn't able to figure out how to select the text i wanted and then set and endnote.
Any suggestions for this would be greatly appreciated!
-Skyler
I am not too familiar with the Word object model, but if you can handle that part I can tell you how to get an instance of Word running and automated. It's quite simple actually.
$Application = New-Object -ComObject Word.Application
$Application.Visible = $true
$Document = $Application.Documents.Add()
The key is Visible = $true otherwise it will be running but hidden. Now you can use all the methods of the Word Application object to create a new doc and automate it. Now if you're using Word 2007's docx format, you can investigate ZIP file extraction cmdlets and access the xml directly in the word doc. But dealing with namespaces in XML is a hassle and may not be as straightforward.
Word Object Model Stuff
ScriptingGuy recently posted a solution to this: http://blogs.technet.com/heyscriptingguy/archive/2009/10/14/hey-scripting-guy-october-14-2009.aspx

Add a "Hyperlink" item type to a list using PowerShell in Sharepoint

I've been a SharePoint admin for a while, and now have been tasked with a bit more of a developer role - which I'm still very much learning. Most things I've been able to figure out on my own or through Google, but this one has me stumped.
For one particular task I need to use PowerShell to script adding items to a list. Normally - not a difficult task. These steps are all over the web. However, I have yet to find anywhere that will tell you how to add a "Hyperlink" type of item to a list.
I can add one using the following code:
$NewItem = $MyList.Items.Add()
$NewItem["My Hyperlink Column"] = $($url.url)
$NewItem.Update()
But I want to set the name/title of the link as well and that's what stumps me. I don't want to have to create a separate column in the list and populate that with the link name, and use code similar to above to populate the url/link.
Does this work for you? I don't have a Sharepoint install available to test on, this is from memory:
$NewItem = $MyList.Items.Add()
$NewItem["My Hyperlink Column"] = "$($url.url), <Title>"
$NewItem.Update()
james
Thanks James! That was very close and I'm thinking would work if I was specifying a single item?
Here's my full solution (with some extra bits):
$enumsite = new-object microsoft.sharepoint.spsite($SubWebUrl)
foreach ($url in $enumsite.allwebs)
{
$NewItem = $MyList.Items.Add()
$NewItem["My Hyperlink Column"] = "$($url.url), $(url.title)"
$NewItem.Update()
}
$enumsite.Dispose()
Perhaps this will help someone else out in the future.