我没有收到所有网站集

时间:2022-07-04 15:20:21

I want to all site collection urls. But when this sorce:

我想要所有网站集网址。但是当这个巫术:

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

I have the next error.

我有下一个错误。

I installed new SKD. But this code is NG.

我安装了新的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)

1 个解决方案

#1


0  

If you want to get all site collections from a tenant using PowerShell, the following PowerShell for your reference.

如果要使用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  

If you want to get all site collections from a tenant using PowerShell, the following PowerShell for your reference.

如果要使用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 '-----------------'
}