Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPSTrust line-ending and encoding policy
#
# PowerShell files run under Windows PowerShell 5.1 on SharePoint servers. Without a
# BOM, Windows PowerShell 5.1 reads .ps1/.psm1/.psd1 as ANSI (the system code page),
# which corrupts any non-ASCII character. We therefore store all PowerShell files as
# UTF-8 with BOM (the BOM is part of the committed content) and check them out with
# CRLF line endings (native on the target servers).
#
# YAML, Markdown and other text files must NOT carry a BOM (it breaks some YAML
# parsers and is unwanted on GitHub-rendered files); they use LF.

* text=auto eol=lf

# PowerShell -- committed with a UTF-8 BOM, checked out with CRLF
*.ps1 text eol=crlf
*.psm1 text eol=crlf
*.psd1 text eol=crlf

# Workflows / docs / config -- no BOM, LF
*.yml text eol=lf
*.yaml text eol=lf
*.md text eol=lf
*.json text eol=lf

# Binary artifacts (release ZIP, screenshots)
*.dll binary
*.png binary
*.zip binary
2 changes: 1 addition & 1 deletion src/Config/CONTOSO-PROD.example.psd1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@{
@{
# SPSTrust configuration file (PowerShell data file).
# Copy this example to '<Application>-<Environment>.psd1' (e.g. CONTOSO-PROD.psd1)
# and adjust the values to match your environment, then run:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function ConvertTo-SPSHtmlEncoded {
function ConvertTo-SPSHtmlEncoded {
<#
.SYNOPSIS
HTML-encodes a string for safe insertion into generated HTML reports.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSReportCardHtml {
function Get-SPSReportCardHtml {
<#
.SYNOPSIS
Builds the HTML for one summary "card" (a big number plus a label).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSReportHtmlHead {
function Get-SPSReportHtmlHead {
<#
.SYNOPSIS
Returns the document head (with the embedded stylesheet) and the opening body tag.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSReportHtmlScript {
function Get-SPSReportHtmlScript {
<#
.SYNOPSIS
Returns the vanilla-JavaScript block that makes the trust matrix table interactive.
Expand Down
136 changes: 68 additions & 68 deletions src/Modules/SPSTrust.Common/Private/Invoke-SPSCommand.ps1
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
function Invoke-SPSCommand {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$Credential, # Credential to be used for executing the command
[Parameter()]
[Object[]]
$Arguments, # Optional arguments for the script block
[Parameter(Mandatory = $true)]
[ScriptBlock]
$ScriptBlock, # Script block containing the commands to execute
[Parameter(Mandatory = $true)]
[System.String]
$Server # Target server where the commands will be executed
)
$VerbosePreference = 'Continue'
# Base script to ensure the SharePoint Server module is loaded on the remote host
$baseScript = @"
if (`$null -eq (Get-Module -Name SharePointServer))
{
Import-Module -Name SharePointServer -Verbose:`$false -WarningAction SilentlyContinue -DisableNameChecking
}
"@
$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 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) `
-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 any caught exceptions
}
finally {
# Remove the session to clean up
if ($session) {
Remove-PSSession -Session $session
}
}
}
}
function Invoke-SPSCommand {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$Credential, # Credential to be used for executing the command
[Parameter()]
[Object[]]
$Arguments, # Optional arguments for the script block
[Parameter(Mandatory = $true)]
[ScriptBlock]
$ScriptBlock, # Script block containing the commands to execute
[Parameter(Mandatory = $true)]
[System.String]
$Server # Target server where the commands will be executed
)
$VerbosePreference = 'Continue'
# Base script to ensure the SharePoint Server module is loaded on the remote host
$baseScript = @"
if (`$null -eq (Get-Module -Name SharePointServer))
{
Import-Module -Name SharePointServer -Verbose:`$false -WarningAction SilentlyContinue -DisableNameChecking
}
"@

$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 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) `
-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 any caught exceptions
}
finally {
# Remove the session to clean up
if ($session) {
Remove-PSSession -Session $session
}
}
}
}

2 changes: 1 addition & 1 deletion src/Modules/SPSTrust.Common/Public/Backup-SPSJsonFile.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Backup-SPSJsonFile {
function Backup-SPSJsonFile {
<#
.SYNOPSIS
Archives an existing results JSON snapshot into a history folder before it is overwritten.
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/SPSTrust.Common/Public/Clear-SPSLogFolder.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Clear-SPSLogFolder {
function Clear-SPSLogFolder {
<#
.SYNOPSIS
Deletes old files from a folder based on a retention window.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Export-SPSSecurityTokenCertificate {
function Export-SPSSecurityTokenCertificate {
[CmdletBinding()]
param
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Export-SPSTrustReport {
function Export-SPSTrustReport {
<#
.SYNOPSIS
Renders a trust status object (or results JSON file) into a self-contained HTML report.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Export-SPSTrustedRootAuthority {
function Export-SPSTrustedRootAuthority {
[CmdletBinding()]
param
(
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/SPSTrust.Common/Public/Get-SPSFarmId.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSFarmId {
function Get-SPSFarmId {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSPublishedServiceAppPermission {
function Get-SPSPublishedServiceAppPermission {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSPublishedServiceAppProxy {
function Get-SPSPublishedServiceAppProxy {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSPublishedServiceApplication {
function Get-SPSPublishedServiceApplication {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down
44 changes: 22 additions & 22 deletions src/Modules/SPSTrust.Common/Public/Get-SPSServer.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
function Get-SPSServer {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param (
[Parameter(Mandatory = $true)]
[System.String]
$Server, # Name of the SharePoint server
[Parameter()]
[System.Management.Automation.PSCredential]
$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
}
return $result
}
function Get-SPSServer {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param (
[Parameter(Mandatory = $true)]
[System.String]
$Server, # Name of the SharePoint server
[Parameter()]
[System.Management.Automation.PSCredential]
$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
}
return $result
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSTopologyServiceAppPermission {
function Get-SPSTopologyServiceAppPermission {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/SPSTrust.Common/Public/Get-SPSTrustStatus.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSTrustStatus {
function Get-SPSTrustStatus {
<#
.SYNOPSIS
Collects the current cross-farm trust state as a read-only status object.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSTrustedRootAuthority {
function Get-SPSTrustedRootAuthority {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-SPSTrustedServiceTokenIssuer {
function Get-SPSTrustedServiceTokenIssuer {
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function New-SPSPublishedServiceAppProxy {
function New-SPSPublishedServiceAppProxy {
[CmdletBinding()]
param
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Publish-SPSServiceApplication {
function Publish-SPSServiceApplication {
[CmdletBinding()]
param
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Remove-SPSPublishedServiceAppProxy {
function Remove-SPSPublishedServiceAppProxy {
[CmdletBinding()]
param
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Set-SPSPublishedServiceAppPermission {
function Set-SPSPublishedServiceAppPermission {
[CmdletBinding()]
param
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Set-SPSTopologyServiceAppPermission {
function Set-SPSTopologyServiceAppPermission {
[CmdletBinding()]
param
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Set-SPSTrustedRootAuthority {
function Set-SPSTrustedRootAuthority {
[CmdletBinding()]
param
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Set-SPSTrustedServiceTokenIssuer {
function Set-SPSTrustedServiceTokenIssuer {
[CmdletBinding()]
param
(
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/SPSTrust.Common/SPSTrust.Common.psd1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@{
@{
RootModule = 'SPSTrust.Common.psm1'
ModuleVersion = '3.0.0'
GUID = 'e1cce4f2-12de-4923-8e67-f37a081944aa'
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/SPSTrust.Common/SPSTrust.Common.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# =====================================================================================
# =====================================================================================
# SPSTrust.Common - module loader
#
# Dot-sources every *.ps1 in Private/ and Public/, then exports only the public
Expand Down
2 changes: 1 addition & 1 deletion src/SPSTrust.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.SYNOPSIS
SPSTrust is a PowerShell script tool to configure trusted farms in your SharePoint environment.

Expand Down
2 changes: 1 addition & 1 deletion tests/Modules/SPSTrust.Common.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Pester tests for the SPSTrust.Common module.
# Pester tests for the SPSTrust.Common module.
# Resolve repo root - works on both local and CI/CD.

BeforeAll {
Expand Down
2 changes: 1 addition & 1 deletion tests/Modules/SPSTrust.Report.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Pester tests for the SPSTrust.Common reporting/audit functions (2.1.0):
# Pester tests for the SPSTrust.Common reporting/audit functions (2.1.0):
# Get-SPSTrustStatus, Export-SPSTrustReport, Backup-SPSJsonFile and the private
# HTML report helpers.

Expand Down
2 changes: 1 addition & 1 deletion tests/SPSTrust.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Pester tests for SPSTrust.ps1
# Pester tests for SPSTrust.ps1
# Resolve repo root - works on CI/CD (GitHub Actions) and local runs

BeforeAll {
Expand Down
Loading