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

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.

Related

Looking for help on completing this Wsus script if possible

Edited for clarification: The goal is outlined in what I would like to accomplish. Now I don't know if I am headed in the right direction with this. So in a nut shell,
Am I going about this correctly? (example Is this single script possible or do I need multiple scripts? Is there a better process to doing this in powershell?)
How do I achieve my goal with what I have here? It only does part of what I am looking for. The part to list the computers an update should go out to and the status of the update on said computer I am struggling with.
I am not expecting people to write this but help me figure it out. I can't imagine I am the first one to fit these needs, but just haven't found a similar script for assistance.
Backstory:
For the last few weeks I have been teaching myself Powershell to accomplish a wsus reporting goal. I have searched everywhere trying to find a script that I could modify to fit my needs but I feel my limited skills is making that difficult.
Goal: Pre-approval
I am trying to generate a list of updates that are needing to be approved. (This works) But for each update I want to list out the servers who should be getting this update along with the update status. Example: Update KB12345 is needed by server1/server2/server3 and install status equals X. I am just confused as to the best way to handle this. I am ok with exporting to different file formats. TXT for the first part that lists "How many updates need to be approved" and excel for the computer status part. I started playing with computerscope but I was not able to filter it so I can get workstations vs servers. It lists everything all together.
Goal: Verify Installed status
I would like to run a second check against this during/after our maint window so we can confirm everything installed correctly and that report is logged in our change request for audit needs.
Things I have tried:
Checking each computer to see if the update was installed using a different script took way to long and was dependent on the workstation being available. Servers not so much a big deal as they are always up. Servers we can compare against locally if wsus doesn't get updated in time, but I would need to be able to run this so that I can report on the workstations for this month. (I only care about the updates being applied per month. Not outstanding or previous updates.)
I thought about splitting up this into two scripts. One that did the approval list and one that is run after comparing against a list of KB#s in a text file.
I feel this is a bit overkill but in how our SOX auditing this year has been any hiccup or concern was crazy scrutinized.
#Note the "Cleanup" in my script is a local function to ISEprofile that clears everything on each run. This is removed when it is put into production.
Cleanup
[void][reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”)
#Connect to the WSUS Server and create the wsus object
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(‘wsus’,$False,"8530")
#Variables
#Wsus Variables
$Arrivaldate = ”01/12/2021"
#ApprovedStatus could be the following:Any, declined, hasstaleupdateapprovals, latestrevisionapproved, notapproved
$ApprovedStatus = "notapproved"
$InstallationStatus = "NotInstalled"
#Logging Variables
$Logpath = "D:\scripts\ps1\Testing\Logs\Monthlyupdatelist.txt"
#Create a computer scope object
$computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
#Create UpdateScope
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
#Find all clients using the computer target scope
#$wsus.GetComputerTargets($computerscope)
#$Wsus.GetComputerStatus($computerscope,[ Microsoft.UpdateServices.Administration.UpdateSources]::All)
#Find updates based on scope below. Run $updatescope alone to see all the items you can filter by.
$updatescope.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]::$ApprovedStatus
$updatescope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::$InstallationStatus
$updatescope.FromArrivalDate = [datetime]$Arrivaldate
Start-Transcript -Path $Logpath
#This lists how many updates are set in "all updates"
Write-Host "Number of Updates this month to approve:"$wsus.GetUpdateCount($updatescope)
$wsus.GetUpdateStatus($updatescope,$False)
#List out the updates for the month
$Updatelist = $wsus.GetUpdates($updatescope)
$Updatelist | Select Title, UpdateClassificationTitle, KnowledgebaseArticles, ProductTitles, ArrivalDate, IsApproved, IsDeclined
Stop-Transcript

How do I get to a specific table in an Access Database using PowerShell

Any help would be greatly appreciated. I am trying to open an Access Database and then open a specific table named "UserInfo" using PowerShell. At that point, I would modify the records within that table. As for now, I simply want to get to the table. I have this very basic code I saw somewhere else and modified a tad. I have looked everywhere and can't find a solution to getting to this table. Ultimately, I think that I am looking for a method to use in conjunction with DoCmd?
$filename = "Z:\Database2.accdb"
$accdb = New-Object -ComObject access.application
$accdb.Visible = $true
$accdb.OpenCurrentDatabase($filename)
$accdb.DoCmd

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.

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.

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