Skip to content

Instantly share code, notes, and snippets.

@macmula
macmula / gist:a976f326a1f44853f19c
Created October 10, 2014 14:19
Powershell: Zip-Folder / No 3rd party plugins needed
$date = get-date -f yyMMdd
function CountZipItems(
[__ComObject] $zipFile)
{
If ($zipFile -eq $null)
{
Throw "Value cannot be null: zipFile"
}
Write-Host ("Counting items in zip file (" + $zipFile.Self.Path + ")...")
@macmula
macmula / gist:1f427a2b1f16488c7667
Last active August 29, 2015 14:07
ShorterFormatedEvtBU_Script 141010
#HTML Table Settings
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse; vertical-align: top; display: inline-table;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "H2{vertical-align: top; display: inline-block;}"
$a = $a + "div{vertical-align: top; display: inline-block;}"
$a = $a + "</style>"
@macmula
macmula / gist:94f1de36254e5d2f9317
Created October 10, 2014 14:16
EvtBackup141010
$date = get-date -f yyMMdd
#HTML Table Settings
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse; display: inline-block; float: left; }"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "</style>"
@macmula
macmula / gist:1828f1ca077afe92a27f
Created October 6, 2014 11:17
powershell examples
PS C:\Users\tech1> Get-Help Out-File -Examples
NAME
Out-File
SYNOPSIS
Sends output to a file.
-------------------------- EXAMPLE 1 --------------------------
@macmula
macmula / gist:e0db3f0147a04dd505f2
Last active August 29, 2015 14:07
Powershell / Get-help/help *out-file
PS C:\Users\tech1> help *out-file
SYNOPSIS
Sends output to a file.
SYNTAX
PS C:\Users\tech1> help *out-file
NAME
Out-File
SYNOPSIS
Sends output to a file.
SYNTAX
@macmula
macmula / gist:1c2268ac3844812b66ef
Created October 1, 2014 15:20
Emailing an attachment using Powershell
$EmailTo = "helpdesk@derpcompany.com"
$EmailFrom = "derp@gmail.com"
$Subject = "Test"
$Body = "Test Body"
$SMTPServer = "smtp.gmail.com"
$filenameAndPath = "C:\Users\derptech\Desktop\test.txt"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$attachment = New-Object System.Net.Mail.Attachment($filenameAndPath)
$SMTPMessage.Attachments.Add($attachment)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
@macmula
macmula / gist:b5dcc2fe7f0965f6fd15
Created October 1, 2014 15:13
Event viewer report script.
#Generates Event Report
Get-EventLog -LogName Application -Newest 600 -EntryType Error | Sort-Object -Descending Source |
Select-Object -Property EntryType, Source | ConvertTo-Html –title EventReport –pre Application_Errors|
Out-File A:\SA.adm\EvtReports\EventReport.htm
Get-EventLog -LogName Security -Newest 600 -EntryType FailureAudit | Sort-Object -Descending Source |
Select-Object -Property EntryType, Source | ConvertTo-Html –pre Security_Errors|
Out-File –append A:\SA.adm\EvtReports\EventReport.htm
@macmula
macmula / gist:a288ba662f0d389a46df
Created October 1, 2014 14:55
Even Viewer backup, check, report and clean tool. No mailer added.
#Generates Event Report
Get-EventLog -LogName Application -Newest 600 -EntryType Error | Sort-Object -Descending Source | Select-Object -Property EntryType, Source | ConvertTo-Html –title EventReport –pre Application_Errors| Out-File A:\SA.adm\EvtReports\EventReport.htm
Get-EventLog -LogName Security -Newest 600 -EntryType FailureAudit | Sort-Object -Descending Source | Select-Object -Property EntryType, Source | ConvertTo-Html –pre Security_Errors| Out-File –append A:\SA.adm\EvtReports\EventReport.htm
Get-EventLog -LogName System -Newest 600 -EntryType Error | Sort-Object -Descending Source | Select-Object -Property EntryType, Source |ConvertTo-Html –pre System_Errors | Out-File –append A:\SA.adm\EvtReports\EventReport.htm
#Rename with current date.
$date = get-date -f yyMMdd
rename-item A:\SA.adm\EvtReports\EventReport.htm -newname ("EventReport_$date.htm")
############################################
Get-EventLog -LogName Application -Newest 600 -EntryType Error
Get-EventLog -LogName Security -Newest 600 -EntryType FailureAudit
Get-EventLog -LogName System -Newest 600 -EntryType Error