Skip to content

Instantly share code, notes, and snippets.

View martin9700's full-sized avatar
💭
Updated Set-CellColor -- CICD built too. Now need to make a module out of this.

MartinPugh martin9700

💭
Updated Set-CellColor -- CICD built too. Now need to make a module out of this.
View GitHub Profile
Function Start-Log {
Param (
[int]$KeepLog = 15
)
$Script:VerbosePreference = "Continue"
$LogPath = Join-Path -Path (Split-Path $Script:MyInvocation.MyCommand.Path) -ChildPath "Logs"
If (-not (Test-Path $LogPath))
{
Try {
Write-Verbose "$(Get-Date): This is a verbose message with timestamp"
$KeepLogsFor = 15
$VerbosePreference = "Continue"
$LogPath = Split-Path $MyInvocation.MyCommand.Path
Get-ChildItem "$LogPath\*.log" | Where LastWriteTime -LT (Get-Date).AddDays(-$KeepLogsFor) | Remove-Item -Confirm:$false
$LogPathName = Join-Path -Path $LogPath -ChildPath "$($MyInvocation.MyCommand.Name)-$(Get-Date -Format 'MM-dd-yyyy').log"
Start-Transcript $LogPathName -Append
SELECT bk.database_name AS Name,
bk.recovery_model AS RecoveryModel,
bk.backup_finish_date AS LastBackupDate,
bk.Type,
bk.backup_size AS LastBackupSize
FROM msdb.dbo.backupset AS bk
INNER JOIN (
SELECT database_name,
MAX(backup_finish_date) AS LastBackupDate,
Type
Switch ($true)
{
{$TotalCount}
{ ... }
{$Tail}
{ ... }
Default
{
While ($Line = $File.ReadLine())
{
Switch ($true)
{
{$TotalCount}
{ ... }
{$Tail}
{
While ($Line = $File.ReadLine())
{
$RawData.Add($Line) | Out-Null
}
Switch ($true)
{
{$TotalCount}
{
$Count = 0
While ($Line = $File.ReadLine())
{
Write-Output $Line
$RawData.Add($Line) | Out-Null
$Count ++
If ($Raw)
{
Write-Output $File.ReadToEnd()
}
Else
{
$RawData = New-Object -TypeName System.Collections.ArrayList
Switch ($true)
Try {
Write-Verbose "Reading $PathName..."
$File = New-Object System.IO.StreamReader -Argument $PathName
}
Catch {
Write-Error "Unable to read $PathName because $($Error[0])"
Exit 999
}
[CmdletBinding(DefaultParameterSetName="Normal")]
Param (
[Parameter(ParameterSetName="Normal",Position=0,ValueFromPipeline)]
[string[]]$Path,
[Parameter(ParameterSetName="Pipe",ValueFromPipelineByPropertyName)]
[string]$Fullname,
[Parameter(ParameterSetName="Raw")]
[Parameter(ParameterSetName="Pipe")]