2017-04-14 2 views
0
$adminUPN="[email protected]" 
$orgName="xxxxxx" 
$userCredential = Get-Credential -UserName $adminUPN -Message "Type the password." 

Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential 

# Begin the 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 already 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 from 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 a farm. 
$webApplFilePath = $currentPath + $inputFileName 

#Output File path of the exported AD Security Groups with Site collection and Group Name details. 
$sitesFilePath = $currentPath + $outFilePath 

#File path of the file which will capture all the errors while running the script. 
$errorPath = $currentPath + $errorFileName + $timeStamp + ".csv" 

# Creating object to write logging into the error and output file 
$sitesFile = New-Object System.IO.StreamWriter $sitesFilePath 
$errorfile = New-Object System.IO.StreamWriter $errorPath 

# Fetching SharePoint WebApplications list from a 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 to add Site Content link in thes where it does 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 and 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) 

     # Get the collection of navigation nodes from the 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 a 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 at Site Collection Url :" + $currentSite.Url)      
       $errorfile.WriteLine($currentSite.Url+"`t"+"`t"+$_.Exception.Message)    
      } 
     } 
     #Export Data to CSV 
     $sitesCollection | export-csv $sitesFile -notypeinformation 
     $site.Dispose() 

    } 

    catch 
    { 
      Write-Host("Exception at Site Collection Url :" +$currentSite.Url)      
      $errorfile.WriteLine($currentSite.Url+"`t"+"SiteCollection"+"`t"+$_.Exception.Message)    
     } 

} 

Below hinzuzufügen, ist der Fehler I Export-Csv bin immer: Kann Argument nicht binden ‚Inputobject‘ in den Parameter, weil es null ist. Unter C: \ Benutzer \ EMXBG \ Downloads \ Script_AddSiteContent \ Script_AddSiteContent \ ScriptForSiteContentLinkQuickLaunch - Copy.ps1: 126 Zeichen: 29 + $ sitesCollection | Export-csv $ sitesFile -notype-Information + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: invalidData: (:) [Export-Csv], ParameterBindingValidationException + FullyQualifiedErrorId: ParameterArgumentValidationErrorNullNotAllowed, Microsoft.PowerShell.Commands.ExportCsvCommandFehler beim Abruf während Powershell-Skript ausgeführt Site Content Link-

Antwort

0

Dieser Fehler ist wahrscheinlich, weil $ sitesCollection leer/null ist. Ich kann nichts in Ihrem Code sehen, der ihm einen Wert zuweist.

+0

OK ja, bitte finden Sie den aktualisierten Code, ich bin nicht in der Lage, einen Wert in der QuickLaunch Variable zu erhalten, es ist nicht die Schnellstart navigationobject –

+0

Ich sehe immer noch keinen Teil des Codes, der einen Wert zu ' $ sitesCollection' –

+0

ja Sie sind richtig, es ging nicht in der Ausnahme, so dass kein Fehler erhalten, wird das Dank aktualisieren –

Verwandte Themen