![]() |
VOOZH | about |
The CData Cmdlets for Microsoft Project are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Microsoft Project.
The Cmdlets are not only a PowerShell interface to Microsoft Project, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Microsoft Project data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for MS Project. To access Microsoft Project data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for MS Project.
Once you have acquired the necessary connection properties, accessing Microsoft Project data in PowerShell can be enabled in three steps.
The User and Password properties, under the Authentication section, must be set to valid Microsoft Project user credentials. In addition, specify a URL to a valid Microsoft Project server organization root or Microsoft Project services file.
Install the module:
Install-Module MicrosoftProjectCmdlets
Connect:
$microsoftproject = Connect-MicrosoftProject -User "$User" -Password "$Password" -URL "$URL"
Search for and retrieve data:
$projectname = "Tax Checker" $projects = Select-MicrosoftProject -Connection $microsoftproject -Table "Projects" -Where "ProjectName = `'$ProjectName`'" $projects
You can also use the Invoke-MicrosoftProject cmdlet to execute SQL commands:
$projects = Invoke-MicrosoftProject -Connection $microsoftproject -Query 'SELECT * FROM Projects WHERE ProjectName = @ProjectName' -Params @{'@ProjectName'='Tax Checker'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for MS Project\lib\System.Data.CData.MicrosoftProject.dll")
Connect to Microsoft Project:
$conn= New-Object System.Data.CData.MicrosoftProject.MicrosoftProjectConnection("User=myuseraccount;Password=mypassword;URL=http://myserver/myOrgRoot;")
$conn.Open()
Instantiate the MicrosoftProjectDataAdapter, execute an SQL query, and output the results:
$sql="SELECT ProjectName, ProjectActualCost from Projects"
$da= New-Object System.Data.CData.MicrosoftProject.MicrosoftProjectDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.projectname $_.projectactualcost
}
Update-MicrosoftProject -Connection $MicrosoftProject -Columns @('ProjectName','ProjectActualCost') -Values @('MyProjectName', 'MyProjectActualCost') -Table Projects -Id "MyId"
$cmd = New-Object System.Data.CData.MicrosoftProject.MicrosoftProjectCommand("UPDATE Projects SET ProjectName='Tax Checker' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.MicrosoftProject.MicrosoftProjectParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-MicrosoftProject -Connection $MicrosoftProject -Table Projects -Columns @("ProjectName", "ProjectActualCost") -Values @("MyProjectName", "MyProjectActualCost")
$cmd = New-Object System.Data.CData.MicrosoftProject.MicrosoftProjectCommand("INSERT INTO Projects (ProjectName) VALUES (@myProjectName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.MicrosoftProject.MicrosoftProjectParameter("@myProjectName","Tax Checker")))
$cmd.ExecuteNonQuery()
Remove-MicrosoftProject -Connection $MicrosoftProject -Table "Projects" -Id "MyId"
$cmd = New-Object System.Data.CData.MicrosoftProject.MicrosoftProjectCommand("DELETE FROM Projects WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.MicrosoftProject.MicrosoftProjectParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the MS Project Data Provider to get started:
Download NowLearn more:
👁 Microsoft Project IconRapidly create and deploy powerful .NET applications that integrate with Microsoft Project data including Tasks, Issues, Projects, Deliverables, and more!