SharePointテナントでサイトのコレクションを生成するPowerShellスクリプトを実行しようとしています。ただし、サイトコレクションの作成を実行しようとすると、エラーが発生します。CSOM PowerShellを使用してサイトコレクションを作成しようとするとエラーが発生する
Exception calling "ExecuteQuery" with "0" argument(s): "Unknown Error" At C:\projects\SP\Scripts\Taxonomy\Add-NavigationTerms1.ps1:120 char:5 + $TenantContext.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ServerException
どうすればこのエラーを回避できますか?どうすれば修正できますか?すべてのあなたの助けをありがとう!ここで
はコードです:
param (
[Parameter(Mandatory = $false)]
[string] $sourceWeb = '',
[string] $destinationWeb = '',
[Parameter(Mandatory = $false)]
[string] $sourceListName = 'CurrentSites', #$sourceListName = 'O365 Sites',
[Parameter(Mandatory = $false)]
[string] $sharepointAdmin = ''
)
<#
Add-Type -Path "C:/Program Files/SharePoint Client Components/Assemblies/Microsoft.Online.SharePoint.Client.Tenant.dll"
Add-Type -Path "C:/Program Files/Common Files/microsoft shared/Web Server Extensions/16/ISAPI/Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:/Program Files/Common Files/microsoft shared/Web Server Extensions/16/ISAPI/Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:/Program Files/Common Files/microsoft shared/Web Server Extensions/16/ISAPI/Microsoft.SharePoint.Client.UserProfiles.dll"
#>
$path = 'C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/15/ISAPI/'
$simpleLinkUrlPropertyName = '_Sys_Nav_SimpleLinkUrl'
$assemblies = 'Microsoft.SharePoint.Client.dll',
'Microsoft.SharePoint.Client.Runtime.dll',
'Microsoft.SharePoint.Client.Taxonomy.dll'
$assemblies | % { Add-Type -Path (Join-Path $path $_) }
Add-Type -Path "C:/Program Files/SharePoint Client Components/Assemblies/Microsoft.Online.SharePoint.Client.Tenant.dll"
#$context = New-Object Microsoft.SharePoint.Client.ClientContext($sourceWeb)
#$password = Read-Host -Prompt 'Please enter your password' -AsSecureString
#$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sharepointAdmin,$password)
$password = ''
#[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
#[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
Function Get-SPOContext([string]$Url, [string]$UserName, [string]$Password) {
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
return $context
}
Function Get-ListItems([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
$list = $Context.Web.Lists.GetByTitle($listTitle)
$Context.Load($list)
$Context.ExecuteQuery()
$qry = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
$items = $list.GetItems($qry)
$Context.Load($items)
$Context.ExecuteQuery()
return $items
}
Function Create-Site-Collection([String]$url, [String]$title) {
$TenantURL = ''
$Title = 'New Published Collection List';
[string]
$TenantUserName = '';
[Security.SecureString]
#$TenantPassword = ConvertTo-SecureString 'Anew6731' -AsPlainText -Force
$TenantPassword = convertto-securestring "Anew6731" -asplaintext -force
#Open the Tenant Administration Context with the Tenant Admin Url
$TenantContext = Get-SPOContext -Url $TenantUrl -UserName $TenantUserName -Password "Anew6731"
#$TenantContext = New-Object Microsoft.SharePoint.Client.ClientContext($TenantUrl)
#$TenantCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($TenantUserName, $TenantPassword)
#$TenantContext.Credentials = $TenantCredentials
#Get the tenant object
$Tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($TenantContext)
#Set the Site Creation Properties values
$TenantProperties = New-Object Microsoft.Online.SharePoint.TenantAdministration.SiteCreationProperties
#$TenantProperties.Url = $url
$TenantProperties.Template = "CMSPUBLISHING#0 "
$TenantProperties.Owner = $TenantUserName
$TenantProperties.StorageMaximumLevel = 1000
$TenantProperties.UserCodeMaximumLevel = 300
$TenantProperties.Title = $title
$TenantContext.Load($Tenant)
$TenantContext.ExecuteQuery()
#$TenantContext.Load($TenantProperties)
#$TenantContext.ExecuteQuery()
#Create the site using the properties
$Tenant.CreateSite($TenantProperties) | Out-Null
Write-Host "Creating site collection "
#Create the site in the tennancy
#$TenantContext.Load($Tenant)
#$TenantContext.Load($spOnlineOperation)
$TenantContext.ExecuteQuery()
#$TenantContext.Dispose()
}
$UserName = $sharepointAdmin
#$Password = Read-Host -Prompt "Enter the password"
$Url = $sourceWeb
$context = Get-SPOContext -Url $Url -UserName $UserName -Password $Password $items = Get-ListItems -Context $context -ListTitle "O365 Sites"
foreach ($item in $items) {
$Context.Load($item)
$Context.ExecuteQuery()
Write-Host $item["NEWURL"]
Write-Host $item["Title"]
#Write-Host $item.FieldValues
Create-Site-Collection -URL $item["NEWURL"] -Title $item["Title"]
#Write-Hsost $item.DisplayName
}
$context.Dispose()
うまく働いていましたSOコードのハイライターは '\ 'がエスケープ文字であると考えるので、読みやすく、ハイライトしやすくなります。したがって、PowerShellは両方をサポートしているので、 '' \ ''を '/'に置き換えました。 – Clijsters
コメントしたコードの一部を削除してください。 [最小限で完全で検証可能なサンプルの作成方法](https://stackoverflow.com/help/mcve)を見てください。 – Clijsters