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
10 changes: 7 additions & 3 deletions scripts/powershell/DiskUsageReport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
an email if any drive has less than 10% free space.
#>

[CmdletBinding()]
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[string[]]$Volume,
[ValidateRange(1,100)]
[int]$AlertThreshold = 20,
[string]$CsvPath,
[string]$SmtpServer,
[int]$SmtpPort = 25,
[ValidatePattern('^\d{2,5}$')]
[string]$SmtpPort = '25',
[pscredential]$Credential,
[switch]$UseSsl,
[string]$From,
Expand Down Expand Up @@ -84,7 +86,9 @@ foreach ($entry in $report) {
$smtp = [System.Net.Mail.SmtpClient]::new($SmtpServer, $SmtpPort)
if ($UseSsl) { $smtp.EnableSsl = $true }
if ($Credential) { $smtp.Credentials = $Credential.GetNetworkCredential() }
$smtp.Send($mail)
if ($PSCmdlet.ShouldProcess("send alert email to $To", "Send email")) {
$smtp.Send($mail)
}
}
catch {
Write-Error "Failed to send alert email: $_"
Expand Down
10 changes: 7 additions & 3 deletions scripts/powershell/LinkCrawler.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Parallel execution requires PowerShell 7 or the ThreadJob module; otherwise URLs are tested sequentially.
#>

[CmdletBinding()]
[CmdletBinding(SupportsShouldProcess=$true)]
param (
[Parameter(Mandatory=$true)]
[string]$BaseUrl,
Expand All @@ -48,7 +48,8 @@ param (
[string]$HtmlReportPath,
[string]$NotifyEmail,
[string]$SmtpServer,
[int]$SmtpPort = 25,
[ValidatePattern('^\d{2,5}$')]
[string]$SmtpPort = '25',
[pscredential]$Credential,
[switch]$UseSsl,
[switch]$ToastNotify,
Expand Down Expand Up @@ -212,6 +213,7 @@ $($rows -join "`n")
}

function Send-Notifications {
[CmdletBinding(SupportsShouldProcess=$true)]
param([object[]]$errors)
if (-not $errors) { return }
if ($NotifyEmail -and $SmtpServer) {
Expand All @@ -221,7 +223,9 @@ function Send-Notifications {
$smtp = [System.Net.Mail.SmtpClient]::new($SmtpServer, $SmtpPort)
if ($UseSsl) { $smtp.EnableSsl = $true }
if ($Credential) { $smtp.Credentials = $Credential.GetNetworkCredential() }
$smtp.Send($mail)
if ($PSCmdlet.ShouldProcess("send notification email to $NotifyEmail", "Send email")) {
$smtp.Send($mail)
}
} catch {
Write-Warning "Failed to send email notification: $_"
} finally {
Expand Down
Loading