none
How to create task in PWA with Powershell RRS feed

Answers

All replies

  • See this PowerShell script. It bulk creates projects and tasks. It will give you more code than you need but will show you how to create new tasks :)

    http://gallery.technet.microsoft.com/office/Create-projects-with-tasks-ae97329e

    THanks

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS

    • Marked as answer by Roland_Zeki Thursday, March 21, 2013 7:16 AM
    Wednesday, March 20, 2013 10:38 PM
    Moderator
  • Very nice, exactly what I need.

    Roland

    Thursday, March 21, 2013 7:17 AM
  • Hi Roland,

    I need to create/update a Task from a given project via powershell.
    Did you found a solution without installing the setup.msi file and can you provide me the script?

    Thanks,
    Stefan

    Monday, April 15, 2013 10:41 AM
  • Okay, here my little contribution on how to update a task by powershell. Maybe someone can use ist.

    ##############################################################################################################
    # Update plan by powershell
    ##############################################################################################################
    # PWA
    $Proj_UID = "8925bd7c-bd1b-4545-978e-13d07fdcc7ea" # Testproject 99992
    $pwaUrl = "http://mypwaurl"; #  without / at the end
    $svcProjectUrl = $pwaUrl + "/_vti_bin/PSI/Project.asmx?wsdl"
    $svcProjectProxy = New-WebServiceProxy -uri $svcProjectUrl -useDefaultCredential
    # Check if project is checked out
    #  2'nd parameter is datastore 0=Draft, 1=Published, 2=Archive, 3=Reporting 
    $projects = $svcProjectProxy.ReadProjectStatus($Proj_UID,0,"",0).Project 
    foreach ($project in $projects) { # wir lesen nur ein Projekt
      if ($project -ne "") { 
        Write-Host -ForegroundColor BLUE (">>ReadProjectStatus project.PROJ_UID: " + $project.PROJ_UID);
        Write-Host -ForegroundColor BLUE (">>ReadProjectStatus project.PROJ_NAME: " + $project.PROJ_NAME);
        Write-Host -ForegroundColor BLUE (">>ReadProjectStatus project.PROJ_CHECKOUTDATE: " + $project.PROJ_CHECKOUTDATE);
        Write-Host -ForegroundColor BLUE (">>ReadProjectStatus project.PROJ_CHECKOUTBY: " + $project.PROJ_CHECKOUTBY);
        # -> end search
        break;
      } 
    } # foreach ($project in $projects)
      
    if( !([System.DBNull]::Value.Equals($project.PROJ_CHECKOUTBY)) ) {
      # Project is checked out
      # -> do not edit plan
      $tempString = "Project '" + $project.PROJ_NAME + "' is already checked out since " + $project.PROJ_CHECKOUTDATE + " by '" + $project.PROJ_CHECKOUTBY +"'";
      Write-Host -ForegroundColor RED (">> " + $tempString);
    } else {
        # Project not checked out
        # -> Edit plan
        Write-Host -ForegroundColor green (">> start CheckOutProject");
        $SessionGuid = [System.Guid]::NewGuid() 
        $SessionDescr = "Update Projectplan"  
        $temp = $svcProjectProxy.CheckOutProject($Proj_UID, $SessionGuid, $SessionDescr); 
        # Sample how to read team
        #$projectTeams = $svcProjectProxy.ReadProjectTeam($Proj_UID).ProjectTeam | Select Res_UID, Res_Name, Res_Type 
        #foreach ($projectTeam in $projectTeams) { 
        #  Write-Host -ForegroundColor GREEN (">> projectTeam:" + $projectTeam);
        #  Write-Host -ForegroundColor GREEN (">> projectTeam.Res_UID:" + $projectTeam.Res_UID);
        #  Write-Host -ForegroundColor GREEN (">> projectTeam.Res_Name:" + $projectTeam.Res_Name);
        #  Write-Host -ForegroundColor GREEN (">> projectTeam.Res_Type:" + $projectTeam.Res_Type);
        #} 
        $ProjDataSet = New-Object System.Data.DataSet 
        #  2'nd parameter is entitytype : Project=1, Task=2, Resource=4, Assignment=8, ProjectCustomFields=32, TaskCustomFields=64
        #  3'rd parameter is datastore  : 0=Draft, 1=Published, 2=Archive, 3=Reporting 
        $ProjDataSet = $svcProjectProxy.ReadProjectEntities($Proj_UID,2,0) 
        $projectTasks = $ProjDataSet.Task
        ######################################################
        # Find task 26 to edit
        ######################################################
        foreach ($projectTask in $projectTasks) { 
          Write-Host (">> projectTask.TASK_ID und TASK_NAME:" + $projectTask.TASK_ID + ", " + $projectTask.TASK_NAME + "'");
          if( ([System.DBNull]::Value.Equals($projectTask.TASK_NAME)) ) {
            # do not process empty tasks
            continue;
          }
          if ( $projectTask.TASK_ID -eq 26 ) { 
            # Task 26 found
            # -> Fill Taskname with date and time
            $projectTask.TASK_NAME = [datetime]::Now;
            $projectTask.TASK_START_DATE = [datetime]::Now; 
            # http://msdn.microsoft.com/en-us/library/websvcproject.projectdataset.taskrow.task_dur_fmt(v=office.12).aspx
            $projectTask.TASK_DUR_FMT = 7; # 7=Day, 9=Week, 11=Month, 53=None
            $projectTask.TASK_DUR = 60; # 60 Minutes duration  
          }
        } #foreach ($projectTask in $projectTasks)
        
        ########################################################
        # Now update, publish and checkIn plan
        ########################################################
        
        # Update project
        Write-Host -ForegroundColor green (">> start QueueUpdateProject");
        $NewJobGuid = [system.guid]::NewGuid()
        # http://msdn.microsoft.com/en-us/library/office/ms476428(v=office.12).aspx
        # Only for update
        #http://us.generation-nt.com/answer/generalonlyupdatesallowed-adding-modifying-task-using-psi-help-36615532.html
        $temp = $svcProjectProxy.QueueUpdateProject($NewJobGuid, $SessionGuid, $ProjDataSet, $false); 
        sleep 5
        # publish project
        Write-Host -ForegroundColor green (">> start QueuePublish");
        $NewJobGuid = [system.guid]::NewGuid()
        $temp = $svcProjectProxy.QueuePublish($NewJobGuid, $Proj_UID, "true","") 
        # check in project
        Write-Host -ForegroundColor green (">> start QueueCheckInProject");
        $NewJobGuid = [system.guid]::NewGuid()
        $temp = $svcProjectProxy.QueueCheckInProject($NewJobGuid, $Proj_UID, $false, $SessionGuid, $SessionDescr); 
      
      } # if( !([System.DBNull]::Value.Equals($project.PROJ_CHECKOUTBY)) )
      Write-Host ( "" + (get-date) + " end of powershell")

    Monday, April 29, 2013 12:13 PM