Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
adbertram committed Oct 17, 2017
1 parent fd15783 commit 02db119
Show file tree
Hide file tree
Showing 7 changed files with 542 additions and 74 deletions.
10 changes: 5 additions & 5 deletions File-Folder Management/FileMonitor.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#>
[CmdletBinding()]
param (
[Parameter(Mandatory,ValueFromPipeline)]
[Parameter(Mandatory, ValueFromPipeline)]
[System.Object]$InputObject
)
process {
Expand Down Expand Up @@ -75,7 +75,7 @@ function New-FileMonitor {

## Subscribe to the WMI event using the WMI filter query created above
$WmiFilterParams = @{
'Class' = '__EventFilter'
'Class' = '__EventFilter'
'Namespace' = 'root\subscription'
'Arguments' = @{ Name = $Name; EventNameSpace = 'root\cimv2'; QueryLanguage = 'WQL'; Query = $WmiEventFilterQuery }
}
Expand All @@ -92,15 +92,15 @@ function New-FileMonitor {

## Create the WMI event consumer which will actually consume the event
$WmiConsumerParams = @{
'Class' = 'ActiveScriptEventConsumer'
'Class' = 'ActiveScriptEventConsumer'
'Namespace' = 'root\subscription'
'Arguments' = @{ Name = $Name; ScriptFileName = $VbsScriptFilePath; ScriptingEngine = 'VBscript' }
}
Write-Verbose -Message "Creating WMI consumer using script file name $VbsScriptFilePath"
$WmiConsumer = Set-WmiInstance @WmiConsumerParams

$WmiFilterConsumerParams = @{
'Class' = '__FilterToConsumerBinding'
'Class' = '__FilterToConsumerBinding'
'Namespace' = 'root\subscription'
'Arguments' = @{ Filter = $WmiEventFilterPath; Consumer = $WmiConsumer }
}
Expand Down Expand Up @@ -140,7 +140,7 @@ function Get-FileMonitor {
$Monitor.Consumer = Get-WmiObject @ConsumerParams
if (($Monitor.Values | where { $_ }).Count -eq $Monitor.Keys.Count) {
[pscustomobject]$Monitor
} elseif (($Monitor.Values | where { !$_ }).Count -eq $Monitor.Keys.Count) {
} elseif (-not $Monitor.Binding -and -not $Monitor.Filter) {
$null
} else {
throw 'Mismatch between binding, filter and consumer names exists'
Expand Down
169 changes: 110 additions & 59 deletions File-Folder Management/Invoke-WindowsDiskCleanup.ps1
Original file line number Diff line number Diff line change
@@ -1,65 +1,116 @@
function Invoke-WindowsDiskCleanup {
param()
#requires -Version 5

Write-Log -Message 'Clearing CleanMgr.exe automation settings.'
<#PSScriptInfo
$getItemParams = @{
Path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\*'
Name = 'StateFlags0001'
ErrorAction = 'SilentlyContinue'
.VERSION 1.1
.GUID 0ef579e1-d89d-4e8a-9b9a-f07ab5af1084
.AUTHOR Adam Bertram
.COMPANYNAME Adam the Automator, LLC
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>

<#
.DESCRIPTION
A PowerShell wrapper script to automate the Windows Disk Cleanup utility.
#>

param(
[Parameter()]
[ValidateNotNullOrEmpty()]
[string[]]$Section
)

$sections = @(
'Active Setup Temp Folders',
'BranchCache',
'Content Indexer Cleaner',
'Device Driver Packages',
'Downloaded Program Files',
'GameNewsFiles',
'GameStatisticsFiles',
'GameUpdateFiles',
'Internet Cache Files',
'Memory Dump Files',
'Offline Pages Files',
'Old ChkDsk Files',
'Previous Installations',
'Recycle Bin',
'Service Pack Cleanup',
'Setup Log Files',
'System error memory dump files',
'System error minidump files',
'Temporary Files',
'Temporary Setup Files',
'Temporary Sync Files',
'Thumbnail Cache',
'Update Cleanup',
'Upgrade Discarded Files',
'User file versions',
'Windows Defender',
'Windows Error Reporting Archive Files',
'Windows Error Reporting Queue Files',
'Windows Error Reporting System Archive Files',
'Windows Error Reporting System Queue Files',
'Windows ESD installation files',
'Windows Upgrade Log Files'
)

if ($PSBoundParameters.ContainsKey('Section')) {
if ($Section -notin $sections) {
throw "The section [$($Section)] is not available. Available options are: [$($sections -join ',')]."
}
Get-ItemProperty @getItemParams | Remove-ItemProperty -Name StateFlags0001 -ErrorAction SilentlyContinue

$enabledSections = @(
'Active Setup Temp Folders'
'BranchCache'
'Content Indexer Cleaner'
'Device Driver Packages'
'Downloaded Program Files'
'GameNewsFiles'
'GameStatisticsFiles'
'GameUpdateFiles'
'Internet Cache Files'
'Memory Dump Files'
'Offline Pages Files'
'Old ChkDsk Files'
'Previous Installations'
'Recycle Bin'
'Service Pack Cleanup'
'Setup Log Files'
'System error memory dump files'
'System error minidump files'
'Temporary Files'
'Temporary Setup Files'
'Temporary Sync Files'
'Thumbnail Cache'
'Update Cleanup'
'Upgrade Discarded Files'
'User file versions'
'Windows Defender'
'Windows Error Reporting Archive Files'
'Windows Error Reporting Queue Files'
'Windows Error Reporting System Archive Files'
'Windows Error Reporting System Queue Files'
'Windows ESD installation files'
'Windows Upgrade Log Files'
)

Write-Log -Message 'Adding enabled disk cleanup sections...'
foreach ($keyName in $enabledSections) {
$newItemParams = @{
Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\$keyName"
Name = 'StateFlags0001'
Value = 1
PropertyType = 'DWord'
ErrorAction = 'SilentlyContinue'
}
$null = New-ItemProperty @newItemParams
} else {
$Section = $sections
}

Write-Verbose -Message 'Clearing CleanMgr.exe automation settings.'

$getItemParams = @{
Path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\*'
Name = 'StateFlags0001'
ErrorAction = 'SilentlyContinue'
}
Get-ItemProperty @getItemParams | Remove-ItemProperty -Name StateFlags0001 -ErrorAction SilentlyContinue

Write-Verbose -Message 'Adding enabled disk cleanup sections...'
foreach ($keyName in $Section) {
$newItemParams = @{
Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\$keyName"
Name = 'StateFlags0001'
Value = 1
PropertyType = 'DWord'
ErrorAction = 'SilentlyContinue'
}
$null = New-ItemProperty @newItemParams
}

Write-Log -Message 'Starting CleanMgr.exe...'
Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:1' -NoNewWindow -Wait
Write-Verbose -Message 'Starting CleanMgr.exe...'
Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:1' -NoNewWindow -Wait

Write-Log -Message 'Waiting for CleanMgr and DismHost processes...'
Get-Process -Name cleanmgr,dismhost -ErrorAction SilentlyContinue | Wait-Process
}
Write-Verbose -Message 'Waiting for CleanMgr and DismHost processes...'
Get-Process -Name cleanmgr, dismhost -ErrorAction SilentlyContinue | Wait-Process
43 changes: 43 additions & 0 deletions File-Folder Management/Invoke-WindowsDiskCleanup2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

<#PSScriptInfo
.VERSION 1.0
.GUID 0ef579e1-d89d-4e8a-9b9a-f07ab5af1084
.AUTHOR Adam Bertram
.COMPANYNAME Adam the Automator, LLC
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>

<#
.DESCRIPTION
A PowerShell wrapper script to automate the Windows Disk Cleanup utility.
#>
Param()


55 changes: 45 additions & 10 deletions Inventorying-Reporting Tools/Get-ServerUptimeReport.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
<#

<#PSScriptInfo
.VERSION 1.0
.GUID b918ed36-48fa-4577-b2bf-c4d9225cd095
.AUTHOR Adam Bertram
.COMPANYNAME Adam the Automator, LLC
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>

<#
.SYNOPSIS
This is a script that reads a computer's event log for startup and shutdown events. Once found, it will then compare the
times each of these events to come up with the total time the computer was down for.
.DESCRIPTION
This is a script that reads a computer's event log for startup and shutdown events. Once found, it will then compare the
times each of these events to come up with the total time the computer was down for.
.PARAMETER ComputerName
One computer name you'd like to run the report on.
#>

[CmdletBinding()]
Expand All @@ -17,11 +54,10 @@ param (

$filterHt = @{
'LogName' = 'System'
'ID' = 6005
'ID' = 6005
}
$StartEvents = Get-WinEvent -ComputerName $ComputerName -FilterHashtable $filterHt
if (-not $StartEvents)
{
if (-not $StartEvents) {
throw 'Unable to determine any start times'
}
$StartTimes = $StartEvents.TimeCreated
Expand All @@ -33,15 +69,14 @@ $StopTimes = $StopEvents.TimeCreated

foreach ($startTime in $StartTimes) {
$StopTime = $StopTimes | ? { $_ -gt $StartTime } | select -First 1
if (-not $StopTime)
{
if (-not $StopTime) {
$StopTime = Get-Date
}
$output = [ordered]@{
'Startup' = $StartTime
'Shutdown' = $StopTime
'Startup' = $StartTime
'Shutdown' = $StopTime
'Uptime (Days)' = [math]::Round((New-TimeSpan -Start $StartTime -End $StopTime).TotalDays, 2)
'Uptime (Min)' = [math]::Round((New-TimeSpan -Start $StartTime -End $StopTime).TotalMinutes,2)
'Uptime (Min)' = [math]::Round((New-TimeSpan -Start $StartTime -End $StopTime).TotalMinutes, 2)
}
[pscustomobject]$output

Expand Down
43 changes: 43 additions & 0 deletions Inventorying-Reporting Tools/Get-ServerUptimeReport1.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

<#PSScriptInfo
.VERSION 1.0
.GUID b918ed36-48fa-4577-b2bf-c4d9225cd095
.AUTHOR Adam Bertram
.COMPANYNAME Adam the Automator, LLC
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>

<#
.DESCRIPTION
A simple script to determine the true uptime of one or more servers.
#>
Param()


Loading

0 comments on commit 02db119

Please sign in to comment.