Skip to content

Commit

Permalink
Add Configuration and Usage wiki pages
Browse files Browse the repository at this point in the history
  • Loading branch information
luigilink committed Oct 29, 2024
1 parent 20c420c commit b7d312e
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 233 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The format is based on and uses the types of changes according to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - 2023-10-18
## [Unreleased] - 2023-10-29

### Added

Expand All @@ -24,4 +24,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Wiki Documentation in repository - Add :
- wiki/Home.md
- wiki/Getting-Started.md
- wiki/Configuration.md
- wiki/Usage.md
- .github/workflows/wiki.yml

### Changed

- SPSTrust.ps1:
- Update parameter description
- Add [ValidateScript({ Test-Path $_ -and $_ -like '*.json' })] in ConfigFile parameter
- Add missing comments
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Description

SPSTrust is a PowerShell script tool to configure trust Farm in your SharePoint environment.
SPSTrust is a PowerShell script tool to configure trust Farm in your SharePoint environment. The script follows the documentation: [Share service applications across farms in SharePoint Server](https://learn.microsoft.com/en-us/sharepoint/administration/share-service-applications-across-farms).

It's compatible with all supported versions for SharePoint OnPremises (2016 to Subscription Edition).

Expand Down
78 changes: 37 additions & 41 deletions scripts/Modules/util.psm1
Original file line number Diff line number Diff line change
@@ -1,98 +1,94 @@
#region Import Modules
# Import the custom module 'sps.util.psm1' from the script's directory
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'sps.util.psm1') -Force
#endregion

function Invoke-SPSCommand {
[CmdletBinding()]
param
(
param (
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$Credential,

$Credential, # Credential to be used for executing the command
[Parameter()]
[Object[]]
$Arguments,

$Arguments, # Optional arguments for the script block
[Parameter(Mandatory = $true)]
[ScriptBlock]
$ScriptBlock,

$ScriptBlock, # Script block containing the commands to execute
[Parameter(Mandatory = $true)]
[System.String]
$Server
$Server # Target server where the commands will be executed
)

$VerbosePreference = 'Continue'
# Base script to ensure the SharePoint snap-in is loaded
$baseScript = @"
if (`$null -eq (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue))
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
if (`$null -eq (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue))
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
"@

$invokeArgs = @{
ScriptBlock = [ScriptBlock]::Create($baseScript + $ScriptBlock.ToString())
}
# Add arguments if provided
if ($null -ne $Arguments) {
$invokeArgs.Add("ArgumentList", $Arguments)
}
# Ensure a credential is provided
if ($null -eq $Credential) {
throw 'You need to specify a Credential'
}
else {
Write-Verbose -Message ("Executing using a provided credential and local PSSession " + `
"as user $($Credential.UserName)")

# Running garbage collection to resolve issues related to Azure DSC extention use
Write-Verbose -Message ("Executing using a provided credential and local PSSession " + "as user $($Credential.UserName)")
# Running garbage collection to resolve issues related to Azure DSC extension use
[GC]::Collect()

# Create a new PowerShell session on the target server using the provided credentials
$session = New-PSSession -ComputerName $Server `
-Credential $Credential `
-Authentication CredSSP `
-Name "Microsoft.SharePoint.PSSession" `
-SessionOption (New-PSSessionOption -OperationTimeout 0 `
-IdleTimeout 60000) `
-SessionOption (New-PSSessionOption -OperationTimeout 0 -IdleTimeout 60000) `
-ErrorAction Continue


# Add the session to the invocation arguments if the session is created successfully
if ($session) {
$invokeArgs.Add("Session", $session)
}

try {
# Invoke the command on the target server
return Invoke-Command @invokeArgs -Verbose
}
catch {
throw $_
throw $_ # Throw any caught exceptions
}
finally {
# Remove the session to clean up
if ($session) {
Remove-PSSession -Session $session
}
}
}
}

function Get-SPSServer {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
param (
[Parameter(Mandatory = $true)]
[System.String]
$Server,

$Server, # Name of the SharePoint server
[Parameter()]
[System.Management.Automation.PSCredential]
$InstallAccount
$InstallAccount # Credential for accessing the SharePoint server
)

Write-Verbose "Getting SharePoint Servers of Farm '$Server'"
# Use the Invoke-SPSCommand function to get SharePoint servers
$result = Invoke-SPSCommand -Credential $InstallAccount `
-Arguments $PSBoundParameters `
-Server $Server `
-ScriptBlock {
(Get-SPServer | Where-Object -FilterScript { $_.Role -ne 'Invalid' }).Name
(Get-SPServer | Where-Object -FilterScript { $_.Role -ne 'Invalid' }).Name
}
return $result
}
Expand All @@ -101,29 +97,29 @@ function Clear-SPSLog {
param (
[Parameter(Mandatory = $true)]
[System.String]
$path,

$path, # Path to the log files
[Parameter()]
[System.UInt32]
$Retention = 180
$Retention = 180 # Number of days to retain log files
)

# Check if the log file path exists
if (Test-Path $path) {
# Get the current date
$Now = Get-Date
# Define LastWriteTime parameter based on $days
# Define LastWriteTime parameter based on $Retention
$LastWrite = $Now.AddDays(-$Retention)
# Get files based on lastwrite filter and specified folder
$files = Get-Childitem -Path $path -Filter "$($logFileName)*" | Where-Object -FilterScript {
# Get files based on last write filter and specified folder
$files = Get-ChildItem -Path $path -Filter "$($logFileName)*" | Where-Object -FilterScript {
$_.LastWriteTime -le "$LastWrite"
}
# If files are found, proceed to delete them
if ($files) {
Write-Output '--------------------------------------------------------------'
Write-Output "Cleaning log files in $path ..."
foreach ($file in $files) {
if ($null -ne $file) {
Write-Output "Deleting file $file ..."
Remove-Item $file.FullName | out-null
Remove-Item $file.FullName | Out-Null
}
else {
Write-Output 'No more log files to delete'
Expand Down
Loading

0 comments on commit b7d312e

Please sign in to comment.