powershell - i am sending document with all version and meta data across site collection -


$ver = $host | select version if($ver.version.major -gt 1) {$host.runspace.threadoptions = "reusethread"} if(!(get-pssnapin microsoft.sharepoint.powershell -ea 0)) { write-progress -activity "loading modules" -status "loading microsoft.sharepoint.powershell" add-pssnapin microsoft.sharepoint.powershell }  ## #set static variables ## try{  #sourceweburl url of web contains source list $sourceweburl = "http://bp1amsapt229:14146/agt/sangrcs/"  $destinationfilepath="http://bp1amsapt229:14146/agt/scprcs/scp_ctrld/_tobedeleted/test.docx"  #destinationweburl url of web in want transfer documents $destinationweburl = "http://bp1amsapt229:14146/agt/scprcs/"    $web = get-spweb $sourceweburl    #retrieve destination web using parameter provided $dweb = get-spweb $destinationweburl  $targetfolder="http://bp1amsapt229:14146/agt/scprcs/scp_ctrld/_tobedeleted/"    $sourcefile="http://bp1amsapt229:14146/agt/sangrcs/serenja_ctrld/engineering%20services/sch%20-%20schedule/cs%20-%20control%20systems%20(elec_inst_tele)/bp-swoazz-cs-sch-8204.xlsx" $file = $web.getfile($sourcefile)  #unlock document if locked         if($file.item["locked"] -eq $true)         {             $file.item["wip"]=""             $file.item["locked"]=$false             $file.item.systemupdate($false)         }          $destinationfolder  = $dweb.getfolder($targetfolder)         $versioncount = $file.versions.count         $itemvercount=$file.item.versions.count         $datecreatedon = $file.timecreated.tolocaltime();         $author = $file.item["created by"].tostring()         $spfielduservalue = new-object microsoft.sharepoint.spfielduservalue($web,$author);          $createdby = $spfielduservalue.user         if($createdby -eq $null)         {             $author = $file.item["author"].tostring()             $spfielduservalue = new-object microsoft.sharepoint.spfielduservalue($web,$author);              $createdby = $spfielduservalue.user             if($createdby -eq $null)             {                 $author = $file.item["editor"].tostring()                 $spfielduservalue = new-object microsoft.sharepoint.spfielduservalue($web,$author);                  $createdby = $spfielduservalue.user             }         }         $contenttypeid ="";          for($i=0; $i -le $versioncount; $i++)         {             $boolmajorversion = $false             write-host "file version:" $i             if($i -lt $versioncount)             {                 $fileversion = $file.versions[$i]                 $properties = $fileversion.properties                 $usermodifiedby= $null                 if($i -eq 0)                 {                     $usermodifiedby = $createdby                 }                 else                 {                     #$usermodifiedby = $fileversion.createdby                     $author=$file.item.versions[$itemvercount-$i-1].createdby                     $spfielduservalue = new-object microsoft.sharepoint.spfielduservalue($web,$author);                      $usermodifiedby = $spfielduservalue.user                     if($usermodifiedby -eq $null)                     {                         $author = $file.item["editor"].tostring()                         $spfielduservalue = new-object microsoft.sharepoint.spfielduservalue($web,$author);                          $usermodifiedby = $spfielduservalue.user                     }                 }                 #$datemodifiedon = $fileversion.created.tolocaltime()                 $datemodifiedon = $file.item.versions[$itemvercount-$i-1].created.tolocaltime()                 $comments = $fileversion.checkincomment                 if($comments -eq $null)                 {                     $comments=""                 }                 if($fileversion.versionlabel.endswith("0") -eq $true)                 {                     $boolmajorversion = $true                 }                $filestream = $file.openbinarystream()             }             else             {                  $properties = $file.properties;                  $modifiedby = $file.item["editor"].tostring()                  $spfielduservalue1 = new-object microsoft.sharepoint.spfielduservalue($web,$modifiedby);                   $usermodifiedby = $spfielduservalue1.user                  #$datemodifiedon = $file.timelastmodified.tolocaltime();                  $datemodifiedon = $file.item["modified"].tolocaltime();                  $comments = $file.checkincomment;                  if($comments -eq $null){$comments=""}                  if($file.minorversion -eq $true)                  {                     $boolmajorversion = $true                  }                 $filestream = $file.openbinarystream()             }              if($createdby -eq $null)             {                 $createdby=$web.ensureuser("system account")             }             if($usermodifiedby -eq $null)             {                 $usermodifiedby=$web.ensureuser("system account")             }    $filedest = $destinationfolder.files.add($destinationfilepath, $filestream,$properties,$createdby,$usermodifiedby, $datecreatedon, $datemodifiedon, $comments, $true)    $itemdest = $filedest.item;             $itemdest["created"] = $datecreatedon;             $itemdest["modified"] = $datemodifiedon;             $itemdest["editor"]=$usermodifiedby;            $itemdest["modified by"]=$usermodifiedby;             $contenttypeid = $filedest.item.parentlist.contenttypes[$file.item.contenttype.name].id;             $contenttype = $filedest.item.parentlist.contenttypes[$contenttypeid];             $itemdest["content type"] = $contenttype.name;             $itemdest["content type id"] = $contenttype.id.tostring();             $itemdest.systemupdate($false);             }          write-host -foregroundcolor green "file copied successfully"  } catch{ $_.exception.message } 

i getting error in

$destinationfolder.files.add($destinationfilepath, $filestream,$properties,$createdby,$usermodifiedby, $datecreatedon, $datemodifiedon, $comments, $true)

error message:

exception calling "add" "9" argument(s): "user parameter name: specified value not supported user parameter."

any appreciated.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -