This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write-Verbose "$(Get-Date): This is a verbose message with timestamp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Switch ($true) | |
{ | |
{$TotalCount} | |
{ ... } | |
{$Tail} | |
{ ... } | |
Default | |
{ | |
While ($Line = $File.ReadLine()) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Switch ($true) | |
{ | |
{$TotalCount} | |
{ ... } | |
{$Tail} | |
{ | |
While ($Line = $File.ReadLine()) | |
{ | |
$RawData.Add($Line) | Out-Null | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Switch ($true) | |
{ | |
{$TotalCount} | |
{ | |
$Count = 0 | |
While ($Line = $File.ReadLine()) | |
{ | |
Write-Output $Line | |
$RawData.Add($Line) | Out-Null | |
$Count ++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If ($Raw) | |
{ | |
Write-Output $File.ReadToEnd() | |
} | |
Else | |
{ | |
$RawData = New-Object -TypeName System.Collections.ArrayList | |
Switch ($true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding(DefaultParameterSetName="Normal")] | |
Param ( | |
[Parameter(ParameterSetName="Normal",Position=0,ValueFromPipeline)] | |
[string[]]$Path, | |
[Parameter(ParameterSetName="Pipe",ValueFromPipelineByPropertyName)] | |
[string]$Fullname, | |
[Parameter(ParameterSetName="Raw")] | |
[Parameter(ParameterSetName="Pipe")] |