我没有获得所有网站集

时间:2018-07-26 08:40:38

标签: powershell sharepoint csom

我要所有网站集的网址。但是,当这个理由:

New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Context)

下一个错误。

我安装了新的SKD。但是这段代码是NG。

System.Management.Automation.MethodException: "Tenant" のオーバーロードで、引数の数が "1" であるものが見つかりません。
   場所 System.Management.Automation.Adapter.GetBestMethodAndArguments(String methodName, MethodInformation[] methods, PSMethodInvocationConstraints invocationConstraints, Object[] arguments, Object[]& newArguments)
   場所 System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments)
   場所 Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)

2 个答案:

答案 0 :(得分:0)

如果要使用PowerShell从租户处获取所有网站集,请使用以下PowerShell供您参考。

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"

# Initialize client context
$adminURL = 'https://MyTenant-admin.sharepoint.com/'
$username = 'admin@MyTenant.onmicrosoft.com'
$password = 'MyPassword'
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($adminURL)
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$securePassword)
$clientContext.Credentials = $credentials

# Enumerate all site collections

$tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($clientContext)

$props = $tenant.GetSiteProperties(0, $true)
$clientContext.Load($props)
$clientContext.ExecuteQuery()

foreach($sp in $props)
{
       Write-Host 'Title:' $sp.Title
       Write-Host 'Url:' $sp.Url
       Write-Host '-----------------'
}

答案 1 :(得分:0)

您可以仅使用SPO PowerShell,而无需CSOM。

Connect-SPOService -Url https://tenant-admin.sharepoint.com
Get-SPOSite -Limit All -IncludePersonalSite $true