在PS1文件中调用.EXE之前,我如何启用TLS
我有一个ps1文件,该文件称为.exe,如下: -
Show-Message -Message "Step 1a: Create groups and adding users to it"
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateGroups.exe" "true" $Username $Password
现在将提出以下例外: -
Message: The underlying connection was closed: An unexpected error occurred on a send.
Stacktrace: at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Microsoft.Legal.MatterCenter.Common.ConfigureSharePointContext.ConfigureClientContext(String url, String userId, String password)
at Microsoft.Legal.MatterCenter.CreateGroups.Program.AddGroups(Dictionary`2 listval, List`1 groupData)
Message: The underlying connection was closed: An unexpected error occurred on a send.
Stacktrace: at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Microsoft.Legal.MatterCenter.Common.ConfigureSharePointContext.ConfigureClientContext(String url, String userId, String password)
at Microsoft.Legal.MatterCenter.CreateGroups.Program.DeleteGroups(Dictionary`2 listval, List`1 groupData)
17/06/2022 19:51:04 - Creating group and adding users to it failed
我读了许多文章,其中提到可以通过启用此链接 @ https:// blog。 darrenjrobinson.com/powershell-the-dundering-connection-was-was-closed-an-an-ercected-error-occurred-on-a-a-send/ ,他们提到: -
在调用之前添加以下行-Restmethod或Indoke-webrequest呼叫; [net.ServicePointManager] :: SecurityProtocol = [net.securityprotocoltype] :: tls -bor [net.securityprotocolType] :: Tls11 -bor [net.securityprotocoltype] :: TLS12 ,
但是在我的情况下,我无法修改.exe文件,因此我如何在exe中或打电话之前添加上面的文件。 EXE文件?
在调用PS1文件之前,我尝试运行此操作,但得到了确切的错误,如下: -
PS C:\c\tree\master\cloud\src\deployments\Scripts\Helper Utilities> cd C:\c\tree\master\cloud\src\deployments\Scripts\
PS C:\c\tree\master\cloud\src\deployments\Scripts> $TLS12Protocol = [System.Net.SecurityProtocolType] 'Ssl3 , Tls12'
PS C:\c\tree\master\cloud\src\deployments\Scripts> [System.Net.ServicePointManager]::SecurityProtocol = $TLS12Protocol
PS C:\c\tree\master\cloud\src\deployments\Scripts> .\Deploy.ps1
18/06/2022 12:13:31 - Running with full privileges
18/06/2022 12:13:31 - Starting scripts at: 06/18/2022 12:13:31
18/06/2022 12:13:31 - Clearing all the previous logs...
18/06/2022 12:13:31 - All previous logs cleared
18/06/2022 12:13:31 - Adding SharePoint libraries...
18/06/2022 12:13:31 - Added SharePoint libraries
18/06/2022 12:13:31 - Adding common library functions
18/06/2022 12:13:31 - Added common library functions
18/06/2022 12:13:56 -
18/06/2022 12:13:56 - Running Pre-requisites check...
18/06/2022 12:13:56 -
18/06/2022 12:13:56 - Checking Excel file existence
18/06/2022 12:13:56 - C:\c\tree\master\cloud\src\deployments\MCDeploymentConfig.xlsx
18/06/2022 12:13:56 - Configuration Excel file exists
18/06/2022 12:13:56 - Reading parameters from Excel file...
18/06/2022 12:13:56 - All the parameters are retrieved successfully
18/06/2022 12:13:56 -
18/06/2022 12:13:56 - Running .NET Framework check...
18/06/2022 12:13:56 - .NET Framework Version 4.0 or greater exists
18/06/2022 12:13:56 -
18/06/2022 12:13:56 - Running SharePoint Version check for https://mellowsolutionsgmbh.sharepoint.com...
18/06/2022 12:13:58 - SharePoint Version is: 16.0.0.22601
18/06/2022 12:13:58 - Current SharePoint version is 2013
18/06/2022 12:13:58 -
18/06/2022 12:13:58 - Running check for SharePoint Online library...
18/06/2022 12:13:58 - PowerShell SharePoint Online library is present
18/06/2022 12:13:58 -
18/06/2022 12:13:58 - Running check for Azure PowerShell...
18/06/2022 12:13:58 - Azure PowerShell is present
18/06/2022 12:13:58 -
18/06/2022 12:13:58 - Running check for Workflow Service Application Check...
18/06/2022 12:13:58 - Starting deployment...
18/06/2022 12:13:58 - [email protected]
18/06/2022 12:13:58 - Xoq92450@@
18/06/2022 12:13:58 - Step 1a: Create groups and adding users to it
Message: The underlying connection was closed: An unexpected error occurred on a send.
Stacktrace: at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Microsoft.Legal.MatterCenter.Common.ConfigureSharePointContext.ConfigureClientContext(String url, String userId, String password)
at Microsoft.Legal.MatterCenter.CreateGroups.Program.AddGroups(Dictionary`2 listval, List`1 groupData)
Message: The underlying connection was closed: An unexpected error occurred on a send.
Stacktrace: at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Microsoft.Legal.MatterCenter.Common.ConfigureSharePointContext.ConfigureClientContext(String url, String userId, String password)
at Microsoft.Legal.MatterCenter.CreateGroups.Program.DeleteGroups(Dictionary`2 listval, List`1 groupData)
18/06/2022 12:14:00 - Creating group and adding users to it failed
这是我要运行的Deploy.ps1文件: -
#----------------------------------------------
# Steps performed in this script:
#
# Step 1a: Create groups and adding users to it
# Step 1b: Create configuration lists
# Step 2: Create taxonomy hierarchy
# Step 3: Create site columns and content types
# Step 4: Update search configuration file and upload to SharePoint
# Step 5: Activate SharePoint Server Publishing infrastructure feature on catalog site collection
# Step 6: Creating Site Collection(s)
# Step 7: Update site collection view with field(s)
# Step 8: Create ProvisionMatterList
# Any changes in these steps, kindly update this list. Also update the checkpoint in Revert script
#----------------------------------------------
# The below section would start new PowerShell in elevated mode
param([switch]$Elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
# Get the current directory of the script
Function ScriptRoot {Split-Path $MyInvocation.ScriptName}
$ScriptDirectory = (ScriptRoot)
# Get the parent directory of the script
Function Get-ParentDirectory {Split-Path -Parent(Split-Path $MyInvocation.ScriptName)}
$ParentDirectory = (Get-ParentDirectory)
# Global Variables to be used throughout the scripts
#Set Excel file path
$ExcelFilePath = "$ParentDirectory\MCDeploymentConfig.xlsx"
#Create Log folder if not exist
$LogFolder = "$ScriptDirectory\Logs"
If (-not (Test-Path -Path $LogFolder -PathType Container))
{
New-Item -Path $LogFolder -ItemType directory -Force
}
# Set error log file path
$ErrorLogFile = "$ScriptDirectory\Logs\ErrorLog.txt"
# Set log file path
$LogFile = "$ScriptDirectory\Logs\Log.txt"
# Change log file name if already present
If (Test-Path $LogFile) {
$timestamp = Get-Date -format "dd_MMM_yyyy_HH_mm_ss"
$LogFile = "$ScriptDirectory\Logs\Log_$timestamp.txt"
}
# Set revert log file path
$RevertLogFile = "$ScriptDirectory\Logs\RevertLog.txt"
# Set helper utilities folder path
$HelperPath = "$ScriptDirectory\Helper Utilities"
Set-Location $ScriptDirectory
# Message Types
Add-Type -TypeDefinition @"
public enum MessageType
{
Success,
Warning,
Failure
}
"@
# Function to display message on console
Function Show-Message([string] $Message, [string] $Type, [bool] $Newline = $true)
{
$timestamp = Get-Date -Format G
$Message = $timestamp + " - " + $Message
switch ($Type)
{
([MessageType]::Success)
{
if($Newline) {
Write-Host $Message -ForegroundColor Green
}
else {
Write-Host $Message -ForegroundColor Green -NoNewline
}
}
([MessageType]::Warning)
{
if($Newline) {
Write-Host $Message -ForegroundColor Yellow
}
else {
Write-Host $Message -ForegroundColor Yellow -NoNewline
}
}
([MessageType]::Failure)
{
if($Newline) {
Write-Host $Message -ForegroundColor Red
}
else {
Write-Host $Message -ForegroundColor Red -NoNewline
}
}
Default { Write-Host $Message -ForegroundColor White }
}
# Write into log file
if(-not [String]::IsNullOrEmpty($Message)) {
($Message) | Out-File $LogFile -Append
}
}
if ((Test-Admin) -eq $false) {
if ($elevated)
{
# tried to elevate, did not work, aborting
Show-Message -message "Elevation of privileges did not work, Aborting!" -Type ([MessageType]::Failure)
}
else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
Show-Message -Message "Running with full privileges"
$Date = Get-Date
Show-Message -Message "Starting scripts at: $Date" -Type ([MessageType]::Success)
Function RevertAll($ScriptDirectory, $Checkpoint) {
. "$ScriptDirectory\Revert.ps1" -Checkpoint: $Checkpoint -ScriptDirectory: $ScriptDirectory
}
#----------------------------------------------
# Clear all existing logs from error file or creates a new file
#----------------------------------------------
Show-Message -Message "Clearing all the previous logs..." -Type ([MessageType]::Warning)
"" | Out-File $ErrorLogFile
Clear-Content $ErrorLogFile
"" | Out-File $RevertLogFile
Clear-Content $RevertLogFile
Show-Message -Message "All previous logs cleared" -Type ([MessageType]::Success)
#----------------------------------------------
# Add SharePoint Client DLLs
#----------------------------------------------
Show-Message -Message "Adding SharePoint libraries..." -Type ([MessageType]::Warning)
if ((Test-Path -Path "$HelperPath\Microsoft.SharePoint.Client.dll") -and (Test-Path -Path "$HelperPath\Microsoft.SharePoint.Client.Runtime.dll") -and (Test-Path -Path "$HelperPath\Microsoft.SharePoint.Client.Search.dll")) {
Add-Type -Path (Resolve-Path "$HelperPath\Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "$HelperPath\Microsoft.SharePoint.Client.Runtime.dll")
Add-Type -Path (Resolve-Path "$HelperPath\Microsoft.SharePoint.Client.Search.dll")
Show-Message -Message "Added SharePoint libraries" -Type ([MessageType]::Success)
}
else {
Write-Log $ErrorLogFile "Unable to load SharePoint libraries..."
return $false
}
#----------------------------------------------
# Include Common functions script
#----------------------------------------------
Show-Message -Message "Adding common library functions" -Type ([MessageType]::Warning)
. "$ScriptDirectory\LibraryFunctions.ps1"
Show-Message -Message "Added common library functions" -Type ([MessageType]::Success)
#----------------------------------------------
# Accept required credentials for deployment
#----------------------------------------------
$SPCredential = Get-Credential -Message "Enter credentials to access SharePoint tenant."
If ($Null -eq $SPCredential) {
# Display error message and exit
Write-Log $ErrorLogFile "Failed to get credentials"
return
}
#----------------------------------------------
# Run Pre-requisite checker
#----------------------------------------------
Show-Message -Message ""
. "$ScriptDirectory\PreRequisitesScript.ps1"
$ExcelValues = (Read-FromExcel $ExcelFilePath "Config" ("TenantURL", "TenantAdminURL", "CatalogSiteURL") $ErrorLogFile)
$ExcelValues = $ExcelValues.Split(";")
if($ExcelValues.length -le 0)
{
Write-Log $ErrorLogFile "Error reading values from Excel file. Aborting!"
return $false
}
$TenantUrl = $ExcelValues[0]
$TenantAdminURL=$ExcelValues[1]
$CatalogSiteUrl=$ExcelValues[2]
$Username = $SPCredential.UserName
$Password = $SPCredential.GetNetworkCredential().Password
if($IsValid -eq $true)
{
Show-Message -Message "Starting deployment..."
Show-Message -Message $Username
Show-Message -Message $Password
# Setting current location to "Helper Utilities" folder, in order to run the utility applications
cd $HelperPath
#----------------------------------------------
# Create configuration lists in central repository in SharePoint
#----------------------------------------------
Show-Message -Message "Step 1a: Create groups and adding users to it"
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateGroups.exe" "true" $Username $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating group and adding users to it failed" -Type ([MessageType]::Failure)
RevertAll $ScriptDirectory 1
return
}
else {
Show-Message -Message "Completed creating groups and adding users to it" -Type ([MessageType]::Success)
}
#----------------------------------------------
# Create configuration lists in central repository in SharePoint
#----------------------------------------------
Show-Message -Message "Step 1b: Create configuration lists"
[Environment]::CurrentDirectory = Get-Location
& "$HelperPath\Microsoft.Legal.MatterCenter.ConfigureLists.exe" "false" $Username $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating configuration lists failed" -Type ([MessageType]::Failure)
RevertAll $ScriptDirectory 1
return
}
else {
Show-Message -Message "Completed creating configuration lists" -Type ([MessageType]::Success)
}
#----------------------------------------------
# Configure Taxonomy hierarchy in SharePoint
#----------------------------------------------
Show-Message -Message "Step 2: Create taxonomy hierarchy"
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateTerm.exe" "false" $Username $Password
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateTerm.exe" "true" $Username $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating taxonomy hierarchy failed" -Type ([MessageType]::Failure)
RevertAll $ScriptDirectory 2
return
}
else {
Show-Message -Message "Completed creating taxonomy hierarchy" -Type ([MessageType]::Success)
}
#----------------------------------------------
# Create Site Columns and Content Types
#----------------------------------------------
Show-Message -Message "Step 3: Create site columns and content types"
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateSiteColumns.exe" "false" $Username $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating site columns and content types failed" -Type ([MessageType]::Failure)
RevertAll $ScriptDirectory 3
return
}
else {
Show-Message -Message "Completed creating site columns and content types" -Type ([MessageType]::Success)
}
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateContentTypes.exe" "true" $Username $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating content types failed" -Type ([MessageType]::Failure)
return
}
else {
Show-Message -Message "Completed creating content types" -Type ([MessageType]::Success)
}
#----------------------------------------------
# Update search configuration file and upload to SharePoint
#----------------------------------------------
Show-Message -Message "Step 4: Update Search Configuration files and upload to SharePoint"
& "$HelperPath\Microsoft.Legal.MatterCenter.UpdateAppConfig.exe" "3" $Username $Password "false"
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Updating Search Configuration failed" -Type ([MessageType]::Failure)
RevertAll $ScriptDirectory 4 #Revert from step 3 to 1
return
}
else {
Show-Message -Message "Completed updating search configuration file" -Type ([MessageType]::Success)
}
#----------------------------------------------
# Activate SharePoint Server Publishing Infrastructure
#----------------------------------------------
Show-Message -Message "Step 5: Activating SharePoint Server Publishing Infrastructure at Catalog site collection"
try
{
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($CatalogSiteUrl)
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $SPCredential.Password)
Show-Message -Message "Enabling the Feature with GUID" $PublishingFeatureGuid
$FeatureGuid = [System.Guid] $PublishingFeatureGuid
$SpoSite = $Context.Site
$SpoSite.Features.Add($FeatureGuid, $True, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
$Context.ExecuteQuery()
Show-Message -Message "Activated SharePoint Server Publishing Infrastructure Feature" -Type ([MessageType]::Success)
}
catch [System.Exception]
{
Show-Message -Message "Could not activate SharePoint Server Publishing Infrastructure feature." -Type ([MessageType]::Warning)
#Write-Log $ErrorLogFile $_.Exception.ToString()
}
finally {
$Context.Dispose()
}
#---------------------------------------------------------------------
# Create site collection(s) on SharePoint library
#---------------------------------------------------------------------
Connect-SPOService -url $TenantAdminUrl -Credential $SPCredential
$Rootsite = Get-SPOSite($TenantUrl)
$ReturnedValue = [string[]]$Rootsite.DenyAddAndCustomizePages
If("false" -ne $ReturnedValue.ToLower())
{
Set-SPOSite -Identity $TenantUrl -DenyAddAndCustomizePages $false
}
Show-Message -Message "Step 6: Creating Site Collection(s)"
. "$ScriptDirectory\CreateSiteCollection.ps1" -Username: $Username -Password $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating site collection failed" -Type ([MessageType]::Failure)
}
else {
Show-Message -Message "Completed creating site collection" -Type ([MessageType]::Success)
}
#---------------------------------------------------------------------
# Update site pages view with fields
#---------------------------------------------------------------------
Show-Message -Message "Step 7: Update site collection view with fields"
& "$HelperPath\Microsoft.Legal.MatterCenter.UpdateView.exe" $Username $Password
#----------------------------------------------
# Complete tool error check
#----------------------------------------------
If ((Get-Content $ErrorLogFile) -eq $Null) {
Show-Message -Message "Update site collection view with fields successfully" -Type ([MessageType]::Success)
}
else {
Show-Message -Message "Update site collection view with fields failed" -Type ([MessageType]::Failure)
}
#---------------------------------------------------------------------
# Create Provision Matter List
#---------------------------------------------------------------------
Show-Message -Message "Step 8: Create Provision Matter List"
& "$HelperPath\Microsoft.Legal.MatterCenter.UpdateListPermissions" $Username $Password
#----------------------------------------------
# Complete tool error check
#----------------------------------------------
If ((Get-Content $ErrorLogFile) -eq $Null) {
Show-Message -Message "Deployment completed successfully" -Type ([MessageType]::Success)
}
else {
Show-Message -Message "Deployment failed" -Type ([MessageType]::Failure)
}
}
else
{
Show-Message -Message ""
Show-Message -Message "Deployment failed" -Type ([MessageType]::Failure)
}
$Date = Get-Date
Show-Message -Message "Ended Deployment at: $Date"
谢谢
I have a ps1 file which calls a .exe, as follow:-
Show-Message -Message "Step 1a: Create groups and adding users to it"
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateGroups.exe" "true" $Username $Password
now this will raise the following exception:-
Message: The underlying connection was closed: An unexpected error occurred on a send.
Stacktrace: at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Microsoft.Legal.MatterCenter.Common.ConfigureSharePointContext.ConfigureClientContext(String url, String userId, String password)
at Microsoft.Legal.MatterCenter.CreateGroups.Program.AddGroups(Dictionary`2 listval, List`1 groupData)
Message: The underlying connection was closed: An unexpected error occurred on a send.
Stacktrace: at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Microsoft.Legal.MatterCenter.Common.ConfigureSharePointContext.ConfigureClientContext(String url, String userId, String password)
at Microsoft.Legal.MatterCenter.CreateGroups.Program.DeleteGroups(Dictionary`2 listval, List`1 groupData)
17/06/2022 19:51:04 - Creating group and adding users to it failed
I read many articles which mentioned that this error can be resolved by enabling TLS as mentioned in this link @ https://blog.darrenjrobinson.com/powershell-the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-send/, where they mention :-
Add the following line before your Invoke-RestMethod or Invoke-WebRequest call;
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor
[Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
but in my case i can not modify the .exe file, so how i can add the above in the exe or before calling the .exe?
I tried running this , before calling the PS1 file, but got the exact error , as follow:-
PS C:\c\tree\master\cloud\src\deployments\Scripts\Helper Utilities> cd C:\c\tree\master\cloud\src\deployments\Scripts\
PS C:\c\tree\master\cloud\src\deployments\Scripts> $TLS12Protocol = [System.Net.SecurityProtocolType] 'Ssl3 , Tls12'
PS C:\c\tree\master\cloud\src\deployments\Scripts> [System.Net.ServicePointManager]::SecurityProtocol = $TLS12Protocol
PS C:\c\tree\master\cloud\src\deployments\Scripts> .\Deploy.ps1
18/06/2022 12:13:31 - Running with full privileges
18/06/2022 12:13:31 - Starting scripts at: 06/18/2022 12:13:31
18/06/2022 12:13:31 - Clearing all the previous logs...
18/06/2022 12:13:31 - All previous logs cleared
18/06/2022 12:13:31 - Adding SharePoint libraries...
18/06/2022 12:13:31 - Added SharePoint libraries
18/06/2022 12:13:31 - Adding common library functions
18/06/2022 12:13:31 - Added common library functions
18/06/2022 12:13:56 -
18/06/2022 12:13:56 - Running Pre-requisites check...
18/06/2022 12:13:56 -
18/06/2022 12:13:56 - Checking Excel file existence
18/06/2022 12:13:56 - C:\c\tree\master\cloud\src\deployments\MCDeploymentConfig.xlsx
18/06/2022 12:13:56 - Configuration Excel file exists
18/06/2022 12:13:56 - Reading parameters from Excel file...
18/06/2022 12:13:56 - All the parameters are retrieved successfully
18/06/2022 12:13:56 -
18/06/2022 12:13:56 - Running .NET Framework check...
18/06/2022 12:13:56 - .NET Framework Version 4.0 or greater exists
18/06/2022 12:13:56 -
18/06/2022 12:13:56 - Running SharePoint Version check for https://mellowsolutionsgmbh.sharepoint.com...
18/06/2022 12:13:58 - SharePoint Version is: 16.0.0.22601
18/06/2022 12:13:58 - Current SharePoint version is 2013
18/06/2022 12:13:58 -
18/06/2022 12:13:58 - Running check for SharePoint Online library...
18/06/2022 12:13:58 - PowerShell SharePoint Online library is present
18/06/2022 12:13:58 -
18/06/2022 12:13:58 - Running check for Azure PowerShell...
18/06/2022 12:13:58 - Azure PowerShell is present
18/06/2022 12:13:58 -
18/06/2022 12:13:58 - Running check for Workflow Service Application Check...
18/06/2022 12:13:58 - Starting deployment...
18/06/2022 12:13:58 - [email protected]
18/06/2022 12:13:58 - Xoq92450@@
18/06/2022 12:13:58 - Step 1a: Create groups and adding users to it
Message: The underlying connection was closed: An unexpected error occurred on a send.
Stacktrace: at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Microsoft.Legal.MatterCenter.Common.ConfigureSharePointContext.ConfigureClientContext(String url, String userId, String password)
at Microsoft.Legal.MatterCenter.CreateGroups.Program.AddGroups(Dictionary`2 listval, List`1 groupData)
Message: The underlying connection was closed: An unexpected error occurred on a send.
Stacktrace: at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Microsoft.Legal.MatterCenter.Common.ConfigureSharePointContext.ConfigureClientContext(String url, String userId, String password)
at Microsoft.Legal.MatterCenter.CreateGroups.Program.DeleteGroups(Dictionary`2 listval, List`1 groupData)
18/06/2022 12:14:00 - Creating group and adding users to it failed
Here is the Deploy.ps1 file i am trying to run:-
#----------------------------------------------
# Steps performed in this script:
#
# Step 1a: Create groups and adding users to it
# Step 1b: Create configuration lists
# Step 2: Create taxonomy hierarchy
# Step 3: Create site columns and content types
# Step 4: Update search configuration file and upload to SharePoint
# Step 5: Activate SharePoint Server Publishing infrastructure feature on catalog site collection
# Step 6: Creating Site Collection(s)
# Step 7: Update site collection view with field(s)
# Step 8: Create ProvisionMatterList
# Any changes in these steps, kindly update this list. Also update the checkpoint in Revert script
#----------------------------------------------
# The below section would start new PowerShell in elevated mode
param([switch]$Elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
# Get the current directory of the script
Function ScriptRoot {Split-Path $MyInvocation.ScriptName}
$ScriptDirectory = (ScriptRoot)
# Get the parent directory of the script
Function Get-ParentDirectory {Split-Path -Parent(Split-Path $MyInvocation.ScriptName)}
$ParentDirectory = (Get-ParentDirectory)
# Global Variables to be used throughout the scripts
#Set Excel file path
$ExcelFilePath = "$ParentDirectory\MCDeploymentConfig.xlsx"
#Create Log folder if not exist
$LogFolder = "$ScriptDirectory\Logs"
If (-not (Test-Path -Path $LogFolder -PathType Container))
{
New-Item -Path $LogFolder -ItemType directory -Force
}
# Set error log file path
$ErrorLogFile = "$ScriptDirectory\Logs\ErrorLog.txt"
# Set log file path
$LogFile = "$ScriptDirectory\Logs\Log.txt"
# Change log file name if already present
If (Test-Path $LogFile) {
$timestamp = Get-Date -format "dd_MMM_yyyy_HH_mm_ss"
$LogFile = "$ScriptDirectory\Logs\Log_$timestamp.txt"
}
# Set revert log file path
$RevertLogFile = "$ScriptDirectory\Logs\RevertLog.txt"
# Set helper utilities folder path
$HelperPath = "$ScriptDirectory\Helper Utilities"
Set-Location $ScriptDirectory
# Message Types
Add-Type -TypeDefinition @"
public enum MessageType
{
Success,
Warning,
Failure
}
"@
# Function to display message on console
Function Show-Message([string] $Message, [string] $Type, [bool] $Newline = $true)
{
$timestamp = Get-Date -Format G
$Message = $timestamp + " - " + $Message
switch ($Type)
{
([MessageType]::Success)
{
if($Newline) {
Write-Host $Message -ForegroundColor Green
}
else {
Write-Host $Message -ForegroundColor Green -NoNewline
}
}
([MessageType]::Warning)
{
if($Newline) {
Write-Host $Message -ForegroundColor Yellow
}
else {
Write-Host $Message -ForegroundColor Yellow -NoNewline
}
}
([MessageType]::Failure)
{
if($Newline) {
Write-Host $Message -ForegroundColor Red
}
else {
Write-Host $Message -ForegroundColor Red -NoNewline
}
}
Default { Write-Host $Message -ForegroundColor White }
}
# Write into log file
if(-not [String]::IsNullOrEmpty($Message)) {
($Message) | Out-File $LogFile -Append
}
}
if ((Test-Admin) -eq $false) {
if ($elevated)
{
# tried to elevate, did not work, aborting
Show-Message -message "Elevation of privileges did not work, Aborting!" -Type ([MessageType]::Failure)
}
else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
Show-Message -Message "Running with full privileges"
$Date = Get-Date
Show-Message -Message "Starting scripts at: $Date" -Type ([MessageType]::Success)
Function RevertAll($ScriptDirectory, $Checkpoint) {
. "$ScriptDirectory\Revert.ps1" -Checkpoint: $Checkpoint -ScriptDirectory: $ScriptDirectory
}
#----------------------------------------------
# Clear all existing logs from error file or creates a new file
#----------------------------------------------
Show-Message -Message "Clearing all the previous logs..." -Type ([MessageType]::Warning)
"" | Out-File $ErrorLogFile
Clear-Content $ErrorLogFile
"" | Out-File $RevertLogFile
Clear-Content $RevertLogFile
Show-Message -Message "All previous logs cleared" -Type ([MessageType]::Success)
#----------------------------------------------
# Add SharePoint Client DLLs
#----------------------------------------------
Show-Message -Message "Adding SharePoint libraries..." -Type ([MessageType]::Warning)
if ((Test-Path -Path "$HelperPath\Microsoft.SharePoint.Client.dll") -and (Test-Path -Path "$HelperPath\Microsoft.SharePoint.Client.Runtime.dll") -and (Test-Path -Path "$HelperPath\Microsoft.SharePoint.Client.Search.dll")) {
Add-Type -Path (Resolve-Path "$HelperPath\Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "$HelperPath\Microsoft.SharePoint.Client.Runtime.dll")
Add-Type -Path (Resolve-Path "$HelperPath\Microsoft.SharePoint.Client.Search.dll")
Show-Message -Message "Added SharePoint libraries" -Type ([MessageType]::Success)
}
else {
Write-Log $ErrorLogFile "Unable to load SharePoint libraries..."
return $false
}
#----------------------------------------------
# Include Common functions script
#----------------------------------------------
Show-Message -Message "Adding common library functions" -Type ([MessageType]::Warning)
. "$ScriptDirectory\LibraryFunctions.ps1"
Show-Message -Message "Added common library functions" -Type ([MessageType]::Success)
#----------------------------------------------
# Accept required credentials for deployment
#----------------------------------------------
$SPCredential = Get-Credential -Message "Enter credentials to access SharePoint tenant."
If ($Null -eq $SPCredential) {
# Display error message and exit
Write-Log $ErrorLogFile "Failed to get credentials"
return
}
#----------------------------------------------
# Run Pre-requisite checker
#----------------------------------------------
Show-Message -Message ""
. "$ScriptDirectory\PreRequisitesScript.ps1"
$ExcelValues = (Read-FromExcel $ExcelFilePath "Config" ("TenantURL", "TenantAdminURL", "CatalogSiteURL") $ErrorLogFile)
$ExcelValues = $ExcelValues.Split(";")
if($ExcelValues.length -le 0)
{
Write-Log $ErrorLogFile "Error reading values from Excel file. Aborting!"
return $false
}
$TenantUrl = $ExcelValues[0]
$TenantAdminURL=$ExcelValues[1]
$CatalogSiteUrl=$ExcelValues[2]
$Username = $SPCredential.UserName
$Password = $SPCredential.GetNetworkCredential().Password
if($IsValid -eq $true)
{
Show-Message -Message "Starting deployment..."
Show-Message -Message $Username
Show-Message -Message $Password
# Setting current location to "Helper Utilities" folder, in order to run the utility applications
cd $HelperPath
#----------------------------------------------
# Create configuration lists in central repository in SharePoint
#----------------------------------------------
Show-Message -Message "Step 1a: Create groups and adding users to it"
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateGroups.exe" "true" $Username $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating group and adding users to it failed" -Type ([MessageType]::Failure)
RevertAll $ScriptDirectory 1
return
}
else {
Show-Message -Message "Completed creating groups and adding users to it" -Type ([MessageType]::Success)
}
#----------------------------------------------
# Create configuration lists in central repository in SharePoint
#----------------------------------------------
Show-Message -Message "Step 1b: Create configuration lists"
[Environment]::CurrentDirectory = Get-Location
& "$HelperPath\Microsoft.Legal.MatterCenter.ConfigureLists.exe" "false" $Username $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating configuration lists failed" -Type ([MessageType]::Failure)
RevertAll $ScriptDirectory 1
return
}
else {
Show-Message -Message "Completed creating configuration lists" -Type ([MessageType]::Success)
}
#----------------------------------------------
# Configure Taxonomy hierarchy in SharePoint
#----------------------------------------------
Show-Message -Message "Step 2: Create taxonomy hierarchy"
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateTerm.exe" "false" $Username $Password
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateTerm.exe" "true" $Username $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating taxonomy hierarchy failed" -Type ([MessageType]::Failure)
RevertAll $ScriptDirectory 2
return
}
else {
Show-Message -Message "Completed creating taxonomy hierarchy" -Type ([MessageType]::Success)
}
#----------------------------------------------
# Create Site Columns and Content Types
#----------------------------------------------
Show-Message -Message "Step 3: Create site columns and content types"
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateSiteColumns.exe" "false" $Username $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating site columns and content types failed" -Type ([MessageType]::Failure)
RevertAll $ScriptDirectory 3
return
}
else {
Show-Message -Message "Completed creating site columns and content types" -Type ([MessageType]::Success)
}
& "$HelperPath\Microsoft.Legal.MatterCenter.CreateContentTypes.exe" "true" $Username $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating content types failed" -Type ([MessageType]::Failure)
return
}
else {
Show-Message -Message "Completed creating content types" -Type ([MessageType]::Success)
}
#----------------------------------------------
# Update search configuration file and upload to SharePoint
#----------------------------------------------
Show-Message -Message "Step 4: Update Search Configuration files and upload to SharePoint"
& "$HelperPath\Microsoft.Legal.MatterCenter.UpdateAppConfig.exe" "3" $Username $Password "false"
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Updating Search Configuration failed" -Type ([MessageType]::Failure)
RevertAll $ScriptDirectory 4 #Revert from step 3 to 1
return
}
else {
Show-Message -Message "Completed updating search configuration file" -Type ([MessageType]::Success)
}
#----------------------------------------------
# Activate SharePoint Server Publishing Infrastructure
#----------------------------------------------
Show-Message -Message "Step 5: Activating SharePoint Server Publishing Infrastructure at Catalog site collection"
try
{
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($CatalogSiteUrl)
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $SPCredential.Password)
Show-Message -Message "Enabling the Feature with GUID" $PublishingFeatureGuid
$FeatureGuid = [System.Guid] $PublishingFeatureGuid
$SpoSite = $Context.Site
$SpoSite.Features.Add($FeatureGuid, $True, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
$Context.ExecuteQuery()
Show-Message -Message "Activated SharePoint Server Publishing Infrastructure Feature" -Type ([MessageType]::Success)
}
catch [System.Exception]
{
Show-Message -Message "Could not activate SharePoint Server Publishing Infrastructure feature." -Type ([MessageType]::Warning)
#Write-Log $ErrorLogFile $_.Exception.ToString()
}
finally {
$Context.Dispose()
}
#---------------------------------------------------------------------
# Create site collection(s) on SharePoint library
#---------------------------------------------------------------------
Connect-SPOService -url $TenantAdminUrl -Credential $SPCredential
$Rootsite = Get-SPOSite($TenantUrl)
$ReturnedValue = [string[]]$Rootsite.DenyAddAndCustomizePages
If("false" -ne $ReturnedValue.ToLower())
{
Set-SPOSite -Identity $TenantUrl -DenyAddAndCustomizePages $false
}
Show-Message -Message "Step 6: Creating Site Collection(s)"
. "$ScriptDirectory\CreateSiteCollection.ps1" -Username: $Username -Password $Password
If ((Get-Content $ErrorLogFile) -ne $Null) {
Show-Message -Message "Creating site collection failed" -Type ([MessageType]::Failure)
}
else {
Show-Message -Message "Completed creating site collection" -Type ([MessageType]::Success)
}
#---------------------------------------------------------------------
# Update site pages view with fields
#---------------------------------------------------------------------
Show-Message -Message "Step 7: Update site collection view with fields"
& "$HelperPath\Microsoft.Legal.MatterCenter.UpdateView.exe" $Username $Password
#----------------------------------------------
# Complete tool error check
#----------------------------------------------
If ((Get-Content $ErrorLogFile) -eq $Null) {
Show-Message -Message "Update site collection view with fields successfully" -Type ([MessageType]::Success)
}
else {
Show-Message -Message "Update site collection view with fields failed" -Type ([MessageType]::Failure)
}
#---------------------------------------------------------------------
# Create Provision Matter List
#---------------------------------------------------------------------
Show-Message -Message "Step 8: Create Provision Matter List"
& "$HelperPath\Microsoft.Legal.MatterCenter.UpdateListPermissions" $Username $Password
#----------------------------------------------
# Complete tool error check
#----------------------------------------------
If ((Get-Content $ErrorLogFile) -eq $Null) {
Show-Message -Message "Deployment completed successfully" -Type ([MessageType]::Success)
}
else {
Show-Message -Message "Deployment failed" -Type ([MessageType]::Failure)
}
}
else
{
Show-Message -Message ""
Show-Message -Message "Deployment failed" -Type ([MessageType]::Failure)
}
$Date = Get-Date
Show-Message -Message "Ended Deployment at: $Date"
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论