尽管我知道 sharepoint,但我是 powershell 的新手。我想使用 Powershell 在 sharepoint 中创建一个站点。找到了一些链接,但“Get”命令会引发错误消息。我是否需要进行任何初始配置/设置才能开始使用 powershell wrt sharepoint?请指导...我如何使用 powershell 在 Sharepoint 中创建站点...
谢谢
尽管我知道 sharepoint,但我是 powershell 的新手。我想使用 Powershell 在 sharepoint 中创建一个站点。找到了一些链接,但“Get”命令会引发错误消息。我是否需要进行任何初始配置/设置才能开始使用 powershell wrt sharepoint?请指导...我如何使用 powershell 在 Sharepoint 中创建站点...
谢谢
试试这个,如果你想使用 powershell 远程处理,命令看起来像这样:
Invoke-Command -ComputerName MyComputer `
               -FilePath .\Create-WebSite.ps1 `
               -ArgumentList "MySite", "C:\inetpub\MySite", 443
或在本地:
.\Create-WebSite.ps1 -WebSiteName "MySite" -PathInfo "C:\inetpub\MySite" -Port 443
这是脚本,我将其命名为Create-WebSite.ps1
[cmdletbinding(SupportsShouldProcess=$True,ConfirmImpact='High')]  
Param(  
    [Parameter(Mandatory = $True,Position = 0,ValueFromPipeline = $True)]  
    [string]$WebSiteName,  
    [Parameter(Mandatory = $True,Position = 1,ValueFromPipeline = $True)]  
    [string]$PathInfo,
    [Parameter(Mandatory = $false,Position = 3,ValueFromPipeline = $True)]  
    [int]$Port = 80,
    [Parameter(Mandatory = $false,Position = 4,ValueFromPipeline = $True)]  
    [string]$HostHeader
) 
begin
{
    Import-Module WebAdministration
}
process
{
    ForEach-Object {
        New-Item $PathInfo -ItemType Directory -force
        New-Item "$PathInfo\$WebSiteName" -ItemType Directory -force
        Set-Content "$PathInfo\$WebSiteName\app_offline.htm" "$WebSiteName under maintenance" 
        if ($WhatIfPreference.IsPresent) 
        {
            write-host "What if: Performing operation New-WebAppPool -Name $WebSiteName"
            write-host "What if: Performing operation New-Website -Name $WebSiteName -ApplicationPool $WebSiteName -HostHeader $HostName -PhysicalPath $PathInfo -Port $Port"
        }
        else
        {
            New-WebAppPool -Name $WebSiteName 
            New-Website -Name $WebSiteName `
                        -ApplicationPool $WebSiteName `
                        -HostHeader $HostHeader `
                        -PhysicalPath $PathInfo `
                        -Port $Port `
                        -SSL
            New-WebApplication -Site $WebSiteName `
                               -Name $WebSiteName `
                               -PhysicalPath "$PathInfo\$WebSiteName" `
                               -ApplicationPool $WebSiteName
        }
    }
}
end
{}
要编写管理 SharePoint 的 PowerShell 脚本,您有两个选择
这是您可以在 Powershell ISE 中使用的代码:注意:首先根据您的环境更改变量
,要在 SharePoint 中创建一个站点,您必须创建一个 Web 应用程序,您可以通过以下链接进行操作:
 https ://docs.microsoft .com/en-us/powershell/module/sharepoint-server/new-spwebapplication?view=sharepoint-ps
并创建站点编写此代码
Add-PSSnapin Microsoft.Sharepoint.powershell -ErrorAction SilentlyContinue
#Variables
#-----------------------------------
$SiteURL = "http://contoso:4455/" #the site URL of webapplication which you have created
$SiteName = "sitename" 
$SiteOwner = "domain\farmadmin" #Primary Site Collection Administrator 
$SecondSiteOwner = "Domian\secondadminuser" #Secondary Site Collection Administrator 
$SiteTemplate = "DEV#0" #Developer Site Template for more site template go to https://vladtalkstech.com/2017/03/sharepoint-2016-site-template-id-list-for-powershell.html
# Create Site Collection
New-SPSite -Name $SiteName -Url $SiteURL -Template $SiteTemplate -OwnerAlias $SiteOwner -SecondaryOwnerAlias $SecondSiteOwner -Confirm:$false