0
Iam剛接觸PowerShell,我知道共享點。我想使用Powershell在Sharepoint中創建一個站點。找到一些鏈接,但「獲取」命令會引發錯誤消息。我是否需要執行任何初始配置/設置才能開始使用PowerShell w.r.t sharepoint? PLS指南... 我如何使用PowerShell在SharePoint中創建一個網站...使用PowerShell在SharePoint中創建網站
感謝
Iam剛接觸PowerShell,我知道共享點。我想使用Powershell在Sharepoint中創建一個站點。找到一些鏈接,但「獲取」命令會引發錯誤消息。我是否需要執行任何初始配置/設置才能開始使用PowerShell w.r.t sharepoint? PLS指南... 我如何使用PowerShell在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
這裏的劇本,我把它命名爲創建,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
{}
哎呦,我誤會了如何創建網站的問題,所以如果您需要的話,以下是如何做到的! –
這是一個很好的模式來顯示您的代碼,錯誤,並添加有關您的環境,可以幫助給你一個答案的任何信息。 –
請分享您的代碼或錯誤,以幫助您解決問題 – SigarDave