sharepoint online - Getting Error while running Powershell Script to add Site Content Link -


$adminupn="xxxxx@home500.onmicrosoft.com" $orgname="xxxxxx" $usercredential = get-credential -username $adminupn -message "type password."  connect-sposervice -url https://$orgname-admin.sharepoint.com -credential $usercredential  # begin process $loadinfo1 = [system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint.client") $loadinfo2 = [system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint.client.runtime") $loadinfo3 = [system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint.client.userprofiles")  #add sharepoint powershell snapin if not added $snapin = get-pssnapin | where-object {$_.name -eq 'microsoft.sharepoint.powershell'}  if ($snapin -eq $null)  {         write-host "loading sharepoint powershell snapin"         add-pssnapin "microsoft.sharepoint.powershell"  -ea silentlycontinue }  cls   $starttime = $(get-date -f f)  $timestamp = get-date -format "mm_dd_yy_hh_mm"   #get current folder file path  $invocation = (get-variable myinvocation).value  $currentpath = split-path $invocation.mycommand.path   $currentpath = $currentpath + "\"   #config file path  #$configpath = $currentpath + "config.xml"  $configpath = "c:\users\emxbg\downloads\script_addsitecontent\script_addsitecontent\config.xml"  #fetching details config.xml [xml]$configxml = get-content $configpath  $inputfilename = [string]$configxml.config.constants.inputfilename  $errorfilename = [string]$configxml.config.constants.errorfilename  $outfilepath = [string]$configxml.config.constants.outputfilename   #source file path containing list of webapplications in farm.   $webapplfilepath = $currentpath + $inputfilename   #output file path of exported ad security groups site collection , group name details.   $sitesfilepath = $currentpath + $outfilepath   #file path of file capture errors while running script.   $errorpath = $currentpath + $errorfilename + $timestamp + ".csv"  # creating object write logging error , output file  $sitesfile = new-object system.io.streamwriter  $sitesfilepath  $errorfile = new-object system.io.streamwriter $errorpath  # fetching sharepoint webapplications list csv file $csvdata = import-csv -path $webapplfilepath            $sitesfile.writeline("sitecollectionname"+","+"siteurl") $errorfile.writeline("siteurl"+"`t"+"exceptionlevel"+"`t"+"exceptionmsg");  addsitecontentlink $csvdata        $sitesfile.close()       $errorfile.close()   # function add site content link in thes not exists  function addsitecontentlink($csvdata) {   try      {      $comparetext = "site contents"       foreach ($row in $csvdata)        {          $weburl = $row.weburl         #$username = $row.username         #$password = $row.password              #get web application , credentials              #$securepass = convertto-securestring $password -asplaintext -force          #$ctx = new-object microsoft.sharepoint.client.clientcontext($weburl)         #$ctx.credentials = new-object microsoft.sharepoint.client.sharepointonlinecredentials($username, $securepass)          # collection of navigation nodes quick launch bar         #$web = $ctx.web          $quicklaunch = $weburl.navigation.quicklaunch               try             {                 #iterate through each iten in quick launch menu                 foreach($quicklaunch in $web)                 {                        if ($quicklaunch -contains $comparetext)             {              write-host "site content link exists!"              }                 else              {                 # add new navigation node                 $navnode = new-object microsoft.sharepoint.client.navigationnodecreationinformation                 $navnode.aslastnode = $true                 $navnode.title = "site contents"                 $navnode.url = $web.url + "_layouts/15/viewlsts.aspx"                 $navnode.isexternal = $false                  $ctx.load($quicklaunchcoll.add($navnode))                 $ctx.executequery()             }                 }              }             catch             {                 write-host("exception @ site collection url :" + $currentsite.url)                                     $errorfile.writeline($currentsite.url+"`t"+"`t"+$_.exception.message)                           }         }          #export data csv           $sitescollection | export-csv $sitesfile -notypeinformation          $site.dispose()      }       catch      {             write-host("exception @ site collection url :" +$currentsite.url)                                 $errorfile.writeline($currentsite.url+"`t"+"sitecollection"+"`t"+$_.exception.message)                     }  } 

below error getting export-csv : cannot bind argument parameter 'inputobject' because null. @ c:\users\emxbg\downloads\script_addsitecontent\script_addsitecontent\scriptforsitecontentlinkquicklaunch - copy.ps1:126 char:29 + $sitescollection | export-csv $sitesfile -notypeinformation + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : invaliddata: (:) [export-csv], parameterbindingvalidationexception + fullyqualifiederrorid : parameterargumentvalidationerrornullnotallowed,microsoft.powershell.commands.exportcsvcommand

this error because $sitescollection empty/null. can't see in code assigns value.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -