Skip to content

Commit

Permalink
new scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
adbertram committed Aug 30, 2015
1 parent 8d47d13 commit 66d4b6e
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 0 deletions.
98 changes: 98 additions & 0 deletions ActiveDirectory/Get-DcDiag.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[CmdletBinding(DefaultParameterSetName = 'None')]
[OutputType()]
param
(
[Parameter(ParameterSetName = 'DomainController')]
[ValidateNotNullOrEmpty()]
[string[]]$DomainController,

[Parameter()]
[ValidateNotNullOrEmpty()]
[ValidateSet('DnsForwarders', 'DnsDelegation', 'DnsDynamicUpdate', 'DnsRecordRegistration', 'DnsResolveExtName', 'DnsAll')]
[string[]]$DnsTest,

[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$DnsInternetName,

[Parameter(ParameterSetName = 'DomainWide')]
[ValidateNotNullOrEmpty()]
[string]$DomainName = (Get-ADDomain).DNSRoot,

[Parameter()]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
[string]$DcDiagFilePath = 'C:\Windows\System32\dcdiag.exe'

)
process {
try
{
$TestRegex = '(PASS|WARN|FAIL|n/a)|(PASS|WARN|FAIL|n/a)|(PASS|WARN|FAIL|n/a)|(PASS|WARN|FAIL|n/a)|(PASS|WARN|FAIL|n/a)|(PASS|WARN|FAIL|n/a)'
$AllTestsPassedRegex = 'passed test DNS'
if ($PSCmdlet.ParameterSetName -eq 'DomainController')
{
$ServerTestResults = & $DcDiagFilePath /s:$Dc /test:DNS
}
else
{
$ServerTestResults = & $DcDiagFilePath /a /test:DNS
}
if (-not $ServerTestResults)
{
throw 'Could not parse results'
}
Write-Verbose -Message 'Finished dcdiag.exe execution. Parsing result...'
$ServerResults = [regex]::Matches($ServerTestResults, $TestRegex).Value
$TestResults = @{
'Authentication' = ''
'Basic' = ''
'Forwarders' = ''
'Delegations' = ''
'DynamicUpdates' = ''
'RecordRegistrations' = ''
}
if ($ServerResults -and ($ServerResults.Count -ne 7))
{
Write-Verbose -Message "Successfully parsed dcdiag.exe summary results with $($ServerResults -join ',')"
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'Authentication'; 'Result' = $ServerResults[0] }
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'Basic'; 'Result' = $ServerResults[1] }
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'Forwarders'; 'Result' = $ServerResults[2] }
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'Delegations'; 'Result' = $ServerResults[3] }
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'DynamicUpdates'; 'Result' = $ServerResults[4] }
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'RecordRegistrations'; 'Result' = $ServerResults[5] }
}
elseif (-not $ServerResults)
{
## Either it couldn't parse the test summary values correctly or it passed all the tests and the summary values didn't come up
$ServerResults = [regex]::Matches($ServerTestResults, $AllTestsPassedRegex).Value
if (!$ServerResults)
{
throw "Could not determine test results for DC '$Dc'"
}
else
{ ## It passed all the tests but just didn't display the summary values
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'Authentication'; 'Result' = 'PASS' }
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'Basic'; 'Result' = 'PASS' }
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'Forwarders'; 'Result' = 'PASS' }
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'Delegations'; 'Result' = 'PASS' }
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'DynamicUpdates'; 'Result' = 'PASS' }
$SummaryResults += [pscustomobject]@{ 'DomainController' = $Dc; 'Test' = 'RecordRegistrations'; 'Result' = 'PASS' }
}
}

$SummaryResults = $SummaryResults | group test, result -NoElement
$Output.'Authentication' = "{0} / {1} / {2}" -f ($SummaryResults | where { $_.Name -eq 'Authentication, PASS' }).Count, ($SummaryResults | where { $_.Name -eq 'Authentication, WARN' }).Count, ($SummaryResults | where { $_.Name -eq 'Authentication, FAIL' }).Count
$Output.'Basic' = "{0} / {1} / {2}" -f ($SummaryResults | where { $_.Name -eq 'Basic, PASS' }).Count, ($SummaryResults | where { $_.Name -eq 'Basic, WARN' }).Count, ($SummaryResults | where { $_.Name -eq 'Basic, FAIL' }).Count
$Output.'Forwarders' = "{0} / {1} / {2}" -f ($SummaryResults | where { $_.Name -eq 'Forwarders, PASS' }).Count, ($SummaryResults | where { $_.Name -eq 'Forwarders, WARN' }).Count, ($SummaryResults | where { $_.Name -eq 'Forwarders, FAIL' }).Count
$Output.'Delegations' = "{0} / {1} / {2}" -f ($SummaryResults | where { $_.Name -eq 'Delegations, PASS' }).Count, ($SummaryResults | where { $_.Name -eq 'Delegations, WARN' }).Count, ($SummaryResults | where { $_.Name -eq 'Delegations, FAIL' }).Count
$Output.'Dynamic Updates' = "{0} / {1} / {2}" -f ($SummaryResults | where { $_.Name -eq 'DynamicUpdates, PASS' }).Count, ($SummaryResults | where { $_.Name -eq 'DynamicUpdates, WARN' }).Count, ($SummaryResults | where { $_.Name -eq 'DynamicUpdates, FAIL' }).Count
$Output.'Record Registrations' = "{0} / {1} / {2}" -f ($SummaryResults | where { $_.Name -eq 'RecordRegistrations, PASS' }).Count, ($SummaryResults | where { $_.Name -eq 'RecordRegistrations, WARN' }).Count, ($SummaryResults | where { $_.Name -eq 'RecordRegistrations, FAIL' }).Count

[pscustomobject]$Output
}
catch
{
Write-Error $_.Exception.Message
}
}
142 changes: 142 additions & 0 deletions Random Stuff/Get-TimeSummary (Omnifocus Export Parsing).ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
param (
$OmnifocusTaskFile = 'C:\Users\Adam Bertram\Dropbox\OmniFocus.csv'
)

#region Confguration values
$script:DefaultWeekdayTimeAvail = @{
'Monday' = 10
'Tuesday' = 10
'Wednesday' = 10
'Thursday' = 10
'Friday' = 9
'Saturday' = 6
'Sunday' = 3
}

$TotalReportWeeksOut = 8

$script:Today = Get-Date
#endregion

#region Functions
function Get-WeeklyWorkTime([switch]$ThisWeek)
{
if ($ThisWeek.IsPresent)
{
$ThisSunday = @(@(0..7) | % { $((Get-Date).Date).AddDays($_) } | ? { $_.DayOfWeek -ieq 'Monday' })[0]
(1..(New-TimeSpan -Start $Today -End $ThisSunday).Days | % { $DefaultWeekdayTimeAvail[$Today.AddDays($_).DayofWeek.ToString()] } | Measure-Object -Sum).Sum
}
else
{
($DefaultWeekdayTimeAvail.Values | Measure-Object -Sum).Sum
}
}

function Get-TimeFrame ([datetime]$Date)
{
$ThisSunday = @(@(0..7) | % { $((Get-Date).Date).AddDays($_) } | ? { $_.DayOfWeek -ieq 'Monday' })[0]
if ($Date -lt $ThisSunday)
{
'This Week'
}
elseif ($Date -lt ($ThisSunday.AddDays(7)))
{
'1 Week'
}
elseif ($Date -lt ($ThisSunday.AddDays(14)))
{
'2 Weeks'
}
elseif ($Date -lt ($ThisSunday.AddDays(21)))
{
'3 Weeks'
}
elseif ($Date -lt ($ThisSunday.AddDays(30)))
{
'1 Month'
}
elseif ($Date -lt ($ThisSunday.AddDays(60)))
{
'2 Months'
}
elseif ($Date -lt ($ThisSunday.AddDays(90)))
{
'3 Months'
}
else
{
'A ways off'
}
}
#endregion

$AllTasks = Import-Csv -Path $OmnifocusTaskFile

#region Omnifocus task exclusions

## Projects with a single task in a waiting state
$InactiveProjectIds = ($Alltasks | group project | ? { $_.Group.Count -eq 1 -and ($_.Group.Context -like 'WF*' -or $_.Group.Context -eq 'Waiting') } | % { $projectname = $_.Name; $AllTasks | ? { $_.Name -eq $projectname } }).'task id'

## Projects marked inactive
$InactiveProjectIds += ($Alltasks | ? { $_.Type -eq 'Project' -and $_.Status -eq 'inactive' }).'Task id'

## Get projects to get their due date if a task doesn't have one
$Projects = $AllTasks | ? { !$_.Project }

$ExcludeBlock = {
$_.Context -notlike 'WF*' -and
$_.Context -ne 'Waiting' -and
$_.Context -ne 'Low Priority' -and
$_.Context -ne 'Idea' -and
$_.Project -notlike '*Ideas*' -and
$_.Project -and
$_.'Start Date' -lt $Today -and
$_.'Task ID' -notin $InactiveProjectIds -and
$_.Duration
}
#endregion

$AllTasks | ? $ExcludeBlock | % {
if (-not $_.'Due Date')
{
## Find the due date of the task's project
$ProjectId = $_.'Task Id'.Split('.')[0]
$_.'Due Date' = ($Projects | ? { $_.'Task Id' -eq $ProjectId }).'Due Date'
}
$_
} | select name,
@{ n = 'TimeEstimate'; e = { $_.Duration.TrimEnd('m') / 60 } },
@{ n = 'DateTimeFrame'; e = { Get-TimeFrame -Date $_.'Due Date' } }, @{
n = 'AvailableHours'; e = {
$timeframe = Get-TimeFrame -Date $_.'Due Date';
if ($timeframe -eq 'This Week')
{
Get-WeeklyWorkTime -ThisWeek
}
elseif ($timeframe -like '*Week*')
{
Get-WeeklyWorkTime
}
elseif ($timeframe -eq '1 month')
{
(Get-WeeklyWorkTime) * 4
}
elseif ($timeframe -eq '2 months')
{
(Get-WeeklyWorkTime) * 8
}
elseif ($timeframe -eq '3 months')
{
(Get-WeeklyWorkTime) * 12
}
else
{
'NA'
}
}
} | group DateTimeFrame | select name, @{ n = 'CommittedTime';e={($_.Group.TimeEstimate | Measure-Object -Sum).Sum} } | sort name





Binary file added Random Stuff/wordpress.ps1
Binary file not shown.

0 comments on commit 66d4b6e

Please sign in to comment.