Powershell script to populate CheckinNote values in TFS 2010 - powershell

I am unable to send checkin notes with workspace.checkin method in my powershell script. How can I create custom check in notes and send them in powershell script?
I am using TFS 2010
$pendingChanges = $workspace.GetPendingChanges();
$checkinnote = #{"Some Note"="some value"}
$changesetNumber = $workspace.CheckIn($pendingChanges ,"Comment", $checkinnote,null,null);

Try this:
$pendingChanges = $workspace.GetPendingChanges();
$checkinNoteFieldValue = new-object Microsoft.TeamFoundation.VersionControl.Client.CheckinNoteFieldValue 'Some Note', 'some value'
$checkinNote = new-object Microsoft.TeamFoundation.VersionControl.Client.CheckinNote #($checkinNoteFieldValue)
$changesetNumber = $workspace.CheckIn($pendingChanges, 'Comment', $checkinNote, $null, $null)
The CheckIn method expects type CheckinNote and a CheckinNote is constructed from an array of CheckinNoteFieldValue objects.

Related

Opening multiple MS Access application with powershell

Good day everyone. I'm new to powershell so I don't know what's wrong with this. I have this script to open multiple MS Access at once as you see in the script and it is save in my local drive. If I run this script in VS Code editor, the script is fine and two application is launch. Now if I run this script using mouse Right-Click and Run with powershell. At runtime, both application is visible but after the script completed/done, only one application is running and the other is closed.
$accessMenu = New-Object -ComObject Access.Application
$AccessPath1 = "G:\access1.MDB"
$accessMenu.OpenCurrentDatabase($AccessPath1, $false)
$accessMenu.Visible = $true
$accessLink = New-Object -ComObject Access.Application
$AccessPath2 = "G:\access2.accdb"
$accessLink.OpenCurrentDatabase($AccessPath2, $false)
$accessLink.Visible = $true
Am I missing something here? Thanks in advance for sharing your idea's.
Here is a VBScript that will open multiple dbs. It utilizes Windows Shell object. Create a text file and change the extension to vbs. Double click the file to run.
Dim objFSO1, objFS02, oShell1, oShell2
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set oShell1 = CreateObject("WScript.Shell")
oShell1.Run """G:\access1.MDB"""
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
Set oShell2 = CreateObject("WScript.Shell")
oShell2.Run """G:\access2.accdb"""
The only way I can get multiple databases to open and include a password is in VBA.
Option Compare Database
Option Explicit
Dim accdbObj1 As Access.Application
Dim accdbObj2 As Access.Application
____________________________________________________________________________
Sub test()
Set accdbObj1 = CreateObject("Access.Application")
accdbObj1.OpenCurrentDatabase "C:\Users\Owner\June\Forums\demofile.accdb", , "test"
accdbObj1.Application.Visible = True
Set accdbObj2 = CreateObject("Access.Application")
accdbObj2.OpenCurrentDatabase "C:\Users\Owner\June\DOT\Projects.accdb"
accdbObj2.Application.Visible = True
End Sub
For future preference:
As per #topsail said, by passing UserControl = $true in the instantiated variable of Access.Application it prevents the closing of object/application upon script termination/complete.
In powershell:
$accessObj = New-Object -ComObject Access.Application -Property #{UserControl = $true}
In VBA:
Dim accdbObj
Set accdbObj = CreateObject("Access.Application")
accdbObj.OpenCurrentDatabase "G:\path\test.mdb", , "password"
accdbObj.Application.Visible = True
accdbObj.UserControl = True

clearing a textbox which is in a function

i have a function that create a textbox (info box) and can be called from other functions or from buttons.
function InfoBox ($x,$y,$text){
$TextboxInfoBox = New-Object System.Windows.Forms.TextBox
$TextboxInfoBox.Location = New-Object System.Drawing.Size($x,$y)
$TextboxInfoBox.Size = New-Object System.Drawing.Size(200,800)
# Readonly Textbox.
$TextboxInfoBox.Enabled = $true
$TextboxInfoBox.Text = $text
$TabPanelButtons.Controls.Add($TextboxInfoBox)
}
After i called the textbox once, i am not able to overwrite it with another info message.
the first time i call with all the parameters ($x, $y & $text).
Infobox -x '100' -y '150' -text 'This is the first message'
The second time i only want to give another text. How can i clear the textbox and give only a new text like:
Infobox -text "This is the second message"
Any Ideas?
As commenter wrote, the function has to output the TextBox object so you can reference it later to change the text:
function InfoBox ($x,$y,$text){
$TextboxInfoBox = New-Object System.Windows.Forms.TextBox
$TextboxInfoBox.Location = New-Object System.Drawing.Size($x,$y)
$TextboxInfoBox.Size = New-Object System.Drawing.Size(200,800)
# Readonly Textbox.
$TextboxInfoBox.Enabled = $true
$TextboxInfoBox.Text = $text
$TabPanelButtons.Controls.Add($TextboxInfoBox)
$TextboxInfoBox # Output
}
Contrary to most other programming languages, in PowerShell you normally don't need to use the return statement, except for early return from a function. Simply referring to a variable by name on its own line will output its value from the function.
Now you can store the output in a variable and change the text:
$box = Infobox -x 100 -y 150 -text 'This is the first message'
$box.Text = 'This is the second message'

Running Access Macro in Powershell

I'm trying to run an Access 2010 macro in PowerShell (v4.0 Windows 8.1) with the below code:
$Access = New-Object -com Access.Application
$Access.OpenCurrentDatabase("SomePath", $False, "Password")
$Access.Run("SomeProc")
$Access.CloseCurrentDatabase()
$Access.Quit()
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($Access)
Remove-Variable Access
I get an error on the line $Access.Run("SomeProc") that there's not enough parameters specified:
Exception calling "Run" with "1" argument(s): "Invalid number of parameters. (Exception
from HRESULT: 0x8002000E (DISP_E_BADPARAMCOUNT))"
The procedure SomeProc does not require any parameters.
I've read the msdn article on the run method and only one parameter is required.
I've also tried this workaround which also failed to work for an unrelated reason.
Does anyone know what the cause of the error could be and how to get the method working?
This is a driver issue where the OLEDB libraries aren't loading correctly.
I was able to reproduce your error exactly, and I was able to work around it by opening Powershell from your SysWow directory instead of System32.
Try opening this version of Powershell (you'll have to run set-executionpolicy again), and see if it'll execute your script.
%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe
Helpful link: https://social.msdn.microsoft.com/Forums/en-US/4500877f-0031-426e-869d-bda33d9fe254/microsoftaceoledb120-provider-cannot-be-found-it-may-not-be-properly-installed?forum=adodotnetdataproviders
The C# signature is something like this:
public object Run(string Procedure, ref object Arg1, ... ref object Arg30) ...
It means that COM the Arg optional arguments are not optional in .NET because they are explicitly marked as [ref]. You need to provide all 32 args even if you don't use them.
Assuming you have the following VBA code:
Public Sub Greeting(ByVal strName As String)
MsgBox ("Hello, " & strName & "!"), vbInformation, "Greetings"
End Sub
You can either use call it like this:
$Access = New-Object -com Access.Application
$Access.OpenCurrentDatabase("Database1.accdb")
$runArgs = #([System.Reflection.Missing]::Value) * 31
$runArgs[0] = "Greeting" #Method Name
$runArgs[1] = "Jeno" #First Arg
$Access.GetType().GetMethod("Run").Invoke($Access, $runArgs)
In your case it will be:
$runArgs = #([System.Reflection.Missing]::Value) * 31
$runArgs[0] = "SomeProc"
$Access.GetType().GetMethod("Run").Invoke($Access, $runArgs)
I would probably try to add a helper to the access object:
Add-Member -InputObject $Access -MemberType ScriptMethod -Name "Run2" -Value {
$runArgs = #([System.Reflection.Missing]::Value) * 31
for($i = 0; $i -lt $args.Length; $i++){ $runArgs[$i] = $args[$i] }
$this.GetType().GetMethod("Run").Invoke($this, $runArgs)
}
Then you can use Run2 as you would expect:
$Access.Run2("Greeting", "Jeno")
$Access.Run2("SomeProc")

Trying to use PowerShell to add a Parent Link to a TFS Task

I am trying to add a parent link when I create TFS task via powershell. However, I am only able to add a related link:
function Create-New-WorkItem($projName, $taskType, $title, $state, $assignedTo, $iterationPath, $activity, $BLItem)
{
$tfs = Get-TfsServer
$ws = $tfs.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
$proj = $ws.projects[$projName]
$workitem = $proj.workitemtypes[$taskType].newworkitem()
$workitem.open()
$workitem.title = $title
$workitem.state = $state
$workitem.fields["Assigned To"].value = $assignedTo
$workitem.iterationpath = $iterationPath
$workitem.fields["Activity"].value = $activity
$id = Get-Parent-Link $BLItem
$workitem.links.add($id.ID)
$workitem.close()
$workitem.save()
}
function Get-Parent-Link($backLogItemName)
{
$tfs = Get-TfsServer
$WIQL = #"
SELECT [System.Id]
FROM WorkItems
where [System.Title] = '$backLogItemName'
"#
return $tfs.wit.query($WIQL)
}
How can I add the link as a parent instead of a related?
After some trial and error I finally found a way to accomplish linking a new work item as a child to a parent item i.e. backlog item.
$ws = $tfs.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
$linkType = $ws.WorkItemLinkTypes[[Microsoft.TeamFoundation.WorkItemTracking.Client.CoreLinkTypeReferenceNames]::Hierarchy]
Add the workitem id of the parent you want to link the new child workitem to and create a workitemlink object:
$link = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLink($linkType.ReverseEnd, 1234)
You can then add the link to a workitem:
$workitem.WorkItemLinks.Add($link)
$workitem.save()
You need to create a different link type object. A good exercise of the API can be found on Shai's blog.
http://blogs.microsoft.co.il/shair/2010/02/27/tfs-api-part-22-create-link-between-work-item-parent-child-etc/
The PowerShell for this is almost identical.

How To Execute MS Access Query with OLEDB.12

I am looking for the syntax for executing MS Access named query using Microsoft.ACE.OLEDB.12.0 command object.
I see lots of examples using tables but non for queries yet. Swapping out the table name for the query name seems not to work. i.e. select * from 'myquery'
Here is my code snippet:
$OleDbConn = New-Object "System.Data.OleDb.OleDbConnection";
$OleDbCmd = New-Object "System.Data.OleDb.OleDbCommand";
$OleDbAdapter = New-Object "System.Data.OleDb.OleDbDataAdapter";
$DataTable = New-Object "System.Data.DataTable";
$OleDbConn.Open();
$OleDbCmd.Connection = $OleDbConn;
$OleDbCmd.CommandText = "'myQuery'"; # name query in MS Access db
$OleDbCmd.CommandType = [System.Data.CommandType]::StoredProcedure;
$OleDbAdapter.SelectCommand = $OleDbCmd;
$RowsReturned = $OleDbAdapter.Fill($DataTable);
Write-Host $RowsReturned;
Error: Exception calling "Fill" with "1" argument(s): "The Microsoft Access database engine cannot find the input table or query ''Lab Manual''. Make sure it exists and that its name is spelled correctly."
The trick was to append the command 'Execute' before the query name and use square brackets around the query name.
$OleDbConn = New-Object "System.Data.OleDb.OleDbConnection";
$OleDbCmd = New-Object "System.Data.OleDb.OleDbCommand";
$OleDbAdapter = New-Object "System.Data.OleDb.OleDbDataAdapter";
$DataTable = New-Object "System.Data.DataTable";
$OleDbConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\temp\labmanual.mdb;";
$OleDbCmd.Connection = $OleDbConn;
$OleDbCmd.CommandText = "Execute [myQuery]";
$OleDbAdapter.SelectCommand = $OleDbCmd;
$OleDbConn.Open();
$RowsReturned = $OleDbAdapter.Fill($DataTable);
Write-Host $RowsReturned;
$OleDbConn.Close();