Yet another topic 🙂
Okay so there are many ways to do it even within powershell, for example use the project server commandlets & the same task i have done below in no of steps can be done in very short, however the idea to do this post is to showcase detailed way on how powershell can be leveraged to consume web services & relevant methods, so here it goes, have fun
This article can be also found at : http://gallery.technet.microsoft.com/office/Autopublish-All-Projects-3dc55f13
<# Autopublish All Project Server Projects 🙂 #Author : : Sunil Kumar Singh #> <strong>CLS</strong> # Set your variables $PWAUrl = "http://ServerName/PWA" # initiate the PSI Web Services #Project Web Service $ProjSvcURL = $PWAUrl + "/_vti_bin/PSI/Project.asmx?wsdl" $ProjSvcProxy = <strong>New-WebServiceProxy</strong> <em>-uri</em> $ProjSvcURL <em>-useDefaultCredential</em> #-credential $Credential #Queue web service $QSvcUrl = $pwaUrl + "/_vti_bin/PSI/QueueSystem.asmx?wsdl" $QSvcProxy = <strong>New-WebServiceProxy</strong> <em>-uri</em> $QSvcUrl <em>-useDefaultCredential</em> #-credential $Credential #Create Dataset & Fill with Project List $projDataSet = <strong>New-Object</strong> Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1_vti_bin_PSI_Project_asmx_wsdl.ProjectDataSet $projDataSet = $ProjSvcProxy.ReadProjectList() $PrjDS = $projDataSet.Project #$projDataSet.Tables[0].Rows.Count #CheckOut Project & Publish the Project# foreach ($p in $PrjDS) { <strong>Write-host</strong> <em>-ForegroundColor</em> green $p.PROJ_NAME ":: is being Checked Out for publishing" <strong>`</strong> #Not required, just for illustration in case you would want to use it for update etc.. #$ProjSvcProxy.CheckOutProject($p.PROJ_UID, [System.Guid]::NewGuid(), "Checkout For AutoPublish via Powershell"); sleep 2 <strong>Write-host</strong> <em>-ForegroundColor</em> red $p.PROJ_NAME ":: Will be published now, you may check the queue" <strong>`</strong> $ProjSvcProxy.QueuePublish([System.Guid]::NewGuid(),$p.PROJ_UID, $true,""); sleep 2 #$ProjSvcProxy.QueueCheckInProject([System.Guid]::NewGuid(),$p.PROJ_UID,$true,[System.Guid]::NewGuid(),"Checkin Post Autopublish"); <strong>Write-host</strong> <em>-ForegroundColor</em> yellow $p.PROJ_NAME ":: is being checked in now" <strong>`</strong> }
Need help!
must publish only published projects and work projects do not touch, how to change the code?
Need help! How to automatically publish only the published projects, but not the version “working”
Hi Maxim
In this case you will first need to get the list of all projects by comparing the project based on modified dates, though you can get it from Draft DB and i posted the query here , but as you know tapping into draft db is not supported, hence typical recommendation would be to use PSI for the same once you have identified the non published projects you can, check for the name in the for loop if name matches publish, else don’t something like this if($p.PROJ_NAME =”ProjectName in draft”) then publish
Where should I change in the script? that he published only projects with certain names?
And how to write a full script?
Try this
CLS
# Set your variables
$PWAUrl = “http://ServerName/PWA”
# initiate the PSI Web Services
#Project Web Service
$ProjSvcURL = $PWAUrl + “/_vti_bin/PSI/Project.asmx?wsdl”
$ProjSvcProxy = New-WebServiceProxy -uri $ProjSvcURL -useDefaultCredential #-credential $Credential
# Queue web service
$QSvcUrl = $pwaUrl + “/_vti_bin/PSI/QueueSystem.asmx?wsdl”
$QSvcProxy = New-WebServiceProxy -uri $QSvcUrl -useDefaultCredential #-credential $Credential
#Create Dataset & Fill with Project List
$projDataSet = New-Object Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1_vti_bin_PSI_Project_asmx_wsdl.ProjectDataSet
$projDataSet = $ProjSvcProxy.ReadProjectList()
$PrjDS = $projDataSet.Project
#Read projects From dB
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = “Server=DBServerName;Database=ProjectServer_Draft;Integrated Security=True”
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = “select p.PROJ_NAME, p.Proj_UID from MSP_PROJECTS p where p.WPROJ_LAST_PUB < p.PROJ_LAST_SAVED"
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$UnPublishedDataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($UnPublishedDataSet)
$SqlConnection.Close()
#Compare if not published, CheckOut Project & Publish the Project#
foreach($unProj in $UnPublishedDataSet.Tables[0])
{
Write-host -ForegroundColor blue $unProj.PROJ_NAME ":: is being Checked Out for publishing"
$ProjSvcProxy.CheckOutProject($unProj.PROJ_UID, [System.Guid]::NewGuid(), "Checkout For AutoPublish via Powershell");
sleep 2
Write-host -ForegroundColor red $unProj.PROJ_NAME ":: Will be published now, you may check the queue"
$ProjSvcProxy.QueuePublish([System.Guid]::NewGuid(),$unProj.PROJ_UID, $true,"");
sleep 2
Write-host -ForegroundColor green $unProj.PROJ_NAME “:: is being checked in now"
$ProjSvcProxy.QueueCheckInProject([System.Guid]::NewGuid(),$unProj.PROJ_UID,$true,[System.Guid]::NewGuid(),"Checkin Post Autopublish");
break
}
Hi EpmXperts, need help! Havent ProjectServer_Draft base, there is only ProjectServerPWA_Reporting and writes an error “Invalid object name ‘MSP_PROJECTS’.
Hi EpmXperts, need help! Havent ProjectServer_Draft base, there is only ProjectServerPWA_Reporting and writes an error “Invalid object name ‘MSP_PROJECTS’.
Sorry for delayed reply, have been busy with the Project Conference schedule, however as i mentioned it needs to be executed against draft DB, hope this resolves the issue, please replace the name of your draft Db in the code above
Note: as mentioned in the other post, reading directly from draft DB is not supported scenario
after the publication of data on the project server is not updated, ie ms project is updated, but the project server data is not updated.
This might not be related to publishing of the project, seems your data is not synchronized between MSP & web access, try posting the issue in the forum and i am sure we will help you out there also you would get a faster response
through sql script does not work for some reason, the data is not updated, and if manually via msp, then updated.
Hi EpmXperts,
I tried this script in our 2013 project server environment.
Its running successfully without any error but i checked the projects it did published.