【发布时间】:2021-06-02 01:26:57
【问题描述】:
如何通过 Powershell 远程创建新网站集 我尝试了以下方法,但都失败了 试用一:
# Create a PSCredential Object using the "User" and "Password" parameters that you passed to the job
$SecurePassword = '...............' | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList "domain\user", $SecurePassword
$spms = New-PSSession -ComputerName servername -Credential $cred
$Parameters= @{
Session = $spms
ArgumentList ="siteurl","sitename",'domain\user','domain\user2'
ScriptBlock = { Param ($SiteURL,$SiteName,$SiteOwner,$SecondSiteOwner)
Add-PSSnapin Microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
Function Recreate_Site_Collection ($SiteURL,$SiteName,$SiteTemplate,$SiteOwner,$SecondSiteOwner){
# Delete Site Collection
$site = get-spsite -Identity $SiteURL -ErrorAction SilentlyContinue
if($site){
Write-host "Removing the site $SiteURL" -f Red
Remove-SPSite -Identity $SiteURL -Confirm:$false
}
# Create Site Collection
Write-host "creating the site $SiteURL" -f green
echo $SiteOwner
echo $SecondSiteOwner
New-SPSite -Name $SiteName -Url $SiteURL -Template $SiteTemplate -OwnerAlias $SiteOwner -SecondaryOwnerAlias $SecondSiteOwner -Confirm:$false
}
$SiteTemplate = "DEV#0" #Developer Site Template
Recreate_Site_Collection $SiteURL $SiteName $SiteTemplate $SiteOwner $SecondSiteOwner
}}
Invoke-Command @Parameters
错误: 找不到用户。 但是,如果我在服务器上使用相同的变量运行相同的代码,那么当我以管理员身份运行 PowerShell 时就可以了
试验二:
# Create a PSCredential Object using the "User" and "Password" parameters that you passed to the job
$SecurePassword = '..........' | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList "domain/user", $SecurePassword
$spms = New-PSSession -ComputerName servername -Credential $cred
$Parameters= @{
Session = $spms
ArgumentList = "siteurl","sitename",'domain/user',"1033","DEV#0"
ScriptBlock = { Param ($PortalUrl,$SiteName,$userName,$LCID,$WebTemplate)
$adminSiteUrl = "centraladminurl"
$user = "user"
$pwd = '..............'
$securePwd = ConvertTo-SecureString $pwd -AsPlainText -Force
$cred = New-Object PSCredential($user, $securePwd)
$wsdlUrl = $adminSiteUrl + "/_vti_adm/Admin.asmx?WSDL"
$svc = New-WebServiceProxy -Uri $wsdlUrl -Credential $cred
$svc.Timeout = 300000 # 5 minute timeout
$svc.CreateSite(
$siteUrl, # URL
$siteTitle, # Title
$Description, # Description
$LCID, # LCID 1033 arabic
$WebTemplate, # WebTemplate
$user, # Owner Login
"user", # Owner Name
"mail",
$PortalUrl ,
"portalname"
)}}
Invoke-Command @Parameters
错误: 使用“10”参数调用“CreateSite”的异常:“引发了‘Microsoft.SharePoint.SoapServer.SoapServerException’类型的异常。” 但是,当使用 PowerShell 在服务器本身上以管理员身份运行相同的脚本时,它也可以使用相同的变量
请帮忙 我需要从 Jenkins 自动化 SharePoint 部署,这需要远程 PowerShell 脚本,主要步骤是创建无法建立的站点
【问题讨论】:
-
这个类似的答案可能会有所帮助,看起来您可能会遇到声明身份验证问题:sharepoint.stackexchange.com/questions/108504/…。在运行
CreateSite()之前,$user的值是多少? -
实际上,在这个解决方案中,他使用的是 ADFS,但我使用的是域“windows 用户”,它在本地机器上正常工作,因为我以管理员身份运行 PowerShell,我已经尝试过它,但我无法创建声明,因为我无法创建受信任的登录提供程序
-
请帮助,因为所有部署都无法从任何地方“TFS,Jenkins”自动化,因为如果有任何解决方案而不是 TFS,Jenkins 和 PowerShell,我无法远程重新创建 SharePoint 站点,欢迎您只需要我需要远程重新创建 SharePoint 网站集
标签: powershell sharepoint