mirror of https://github.com/lework/script
lework
4 years ago
10 changed files with 29216 additions and 334 deletions
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,507 @@
@@ -0,0 +1,507 @@
|
||||
function GenerateForm { |
||||
############################################################################################################### |
||||
# Version History: |
||||
# |
||||
# 1.1 - 18/07/2012 : https://gallery.technet.microsoft.com/office/MessageTrackingLog-search-72a5dbc7 |
||||
# 2.0 - 12/19/2015 : Nicolas PRIGENT - www.get-cmd.com |
||||
# New features : search by subject / send results by email / export results in csv file |
||||
# Existing feature corrected : search by event ID did not work. Global variable was not created. |
||||
# Code optimized |
||||
# |
||||
# Description: |
||||
# This script searches the MessageTrackingLog in your Organization. |
||||
# You have to enter valid From Addr or To Addr or the subject and select the date. |
||||
# You can also select a specific event ID. You can leave the blank entry to search the whole TrackingLog. |
||||
# |
||||
############################################################################################################### |
||||
|
||||
#region Import the Assemblies |
||||
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null |
||||
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null |
||||
#endregion |
||||
|
||||
#region Generated Form Objects |
||||
$formTrackLog = New-Object System.Windows.Forms.Form |
||||
$labEventID = New-Object System.Windows.Forms.Label |
||||
$comboBoxEventID = New-Object System.Windows.Forms.ComboBox |
||||
$labEndDate = New-Object System.Windows.Forms.Label |
||||
$labStartDate = New-Object System.Windows.Forms.Label |
||||
$labFrom = New-Object System.Windows.Forms.Label |
||||
$dgResults = New-Object System.Windows.Forms.DataGrid |
||||
$dateTimePickerEnd = New-Object System.Windows.Forms.DateTimePicker |
||||
$dateTimePickerStart = New-Object System.Windows.Forms.DateTimePicker |
||||
$txtBoxRecipients = New-Object System.Windows.Forms.TextBox |
||||
$txtBoxSenders = New-Object System.Windows.Forms.TextBox |
||||
$buttonGo = New-Object System.Windows.Forms.Button |
||||
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState |
||||
$labTo = New-Object System.Windows.Forms.Label |
||||
$labSubject = New-Object System.Windows.Forms.Label |
||||
$txtBoxSubject = New-Object System.Windows.Forms.TextBox |
||||
$txtBoxMail = New-Object System.Windows.Forms.TextBox |
||||
$txtBoxCSV = New-Object System.Windows.Forms.TextBox |
||||
$chkBoxCSV = New-Object System.Windows.Forms.CheckBox |
||||
$chkBoxMail = New-Object System.Windows.Forms.CheckBox |
||||
$txtBoxFromMail = New-Object System.Windows.Forms.TextBox |
||||
$txtBoxToMail = New-Object System.Windows.Forms.TextBox |
||||
$txtBoxCSV = New-Object System.Windows.Forms.TextBox |
||||
#endregion Generated Form Objects |
||||
|
||||
#---------------------------------------------- |
||||
#Generated Event Script Blocks |
||||
#---------------------------------------------- |
||||
|
||||
Add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010 |
||||
|
||||
$processData= |
||||
{ |
||||
#This section determine the date and puts it in a working format |
||||
$array = New-Object System.Collections.ArrayList |
||||
$date1 = get-Date -date $dateTimePickerStart.value -uformat "%m/%d/%Y 00:00:01" |
||||
$date3 = [System.DateTime]$date1 |
||||
$date2 = get-Date -date $dateTimePickerEnd.value -uformat "%m/%d/%Y 23:59:59" |
||||
$date4 = [System.DateTime]$date2 |
||||
$Sort = "TimeStamp" |
||||
|
||||
if ($ChoiceEventID -eq "BADMAIL" -or $ChoiceEventID -eq "DEFER" -or $ChoiceEventID -eq "DELIVER" -or $ChoiceEventID -eq "SEND" -or $ChoiceEventID -eq "DSN" -or $ChoiceEventID -eq "FAIL" -or $ChoiceEventID -eq "POISONMESSAGE" -or $ChoiceEventID -eq "RECEIVE" -or $ChoiceEventID -eq "REDIRECT" -or $ChoiceEventID -eq "RESOLVE" -or $ChoiceEventID -eq "SUBMIT" -or $ChoiceEventID -eq "TRANSFER" -or $ChoiceEventID -eq "EXPAND") |
||||
{ |
||||
$EventID = $ChoiceEventID |
||||
} |
||||
else |
||||
{ |
||||
$EventID = "" |
||||
} |
||||
|
||||
if ( $EventID -ne "") |
||||
{ |
||||
if(($txtBoxRecipients.text -eq "") -and ($txtBoxSenders.text -eq "") -and ($txtBoxSubject.text -eq "")) |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -start $date3 -end $date4 -EventID $EventID -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif (($txtBoxRecipients.text -eq "") -and ($txtBoxSenders.text -eq "")) |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -MessageSubject $txtBoxSubject.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif (($txtBoxSubject.text -eq "") -and ($txtBoxSenders.text -eq "")) |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif (($txtBoxSubject.text -eq "") -and ($txtBoxRecipients.text -eq "")) |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -Sender $txtBoxSenders.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif ($txtBoxRecipients.text -eq "") |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -Sender $txtBoxSenders.text -MessageSubject $txtBoxSubject.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif ($txtBoxSenders.text -eq "") |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -MessageSubject $txtBoxSubject.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif ($txtBoxSubject.text -eq "") |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -sender $txtBoxSenders.text -EventID $EventID -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
if(($txtBoxRecipients.text -eq "") -and ($txtBoxSenders.text -eq "") -and ($txtBoxSubject.text -eq "")) |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif (($txtBoxRecipients.text -eq "") -and ($txtBoxSenders.text -eq "")) |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -MessageSubject $txtBoxSubject.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif (($txtBoxSubject.text -eq "") -and ($txtBoxSenders.text -eq "")) |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject,EventID, serverhostname | sort $sort |
||||
} |
||||
elseif (($txtBoxSubject.text -eq "") -and ($txtBoxRecipients.text -eq "")) |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -Sender $txtBoxSenders.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif ($txtBoxRecipients.text -eq "") |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -Sender $txtBoxSenders.text -MessageSubject $txtBoxSubject.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif ($txtBoxSenders.text -eq "") |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -MessageSubject $txtBoxSubject.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
elseif ($txtBoxSubject.text -eq "") |
||||
{ |
||||
$ausgabe = Get-MessageTrackingLog -Recipients $txtBoxRecipients.text -sender $txtBoxSenders.text -start $date3 -end $date4 -resultsize unlimited | Select-object Timestamp, sender, @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, messagesubject, EventID, serverhostname | sort $sort |
||||
} |
||||
} |
||||
|
||||
if ($ausgabe) { |
||||
$array.addrange($ausgabe) |
||||
$dgResults.datasource = $array |
||||
$array | export-csv "MessageTrackingGUI.log" |
||||
if ($chkBoxCSV.Checked) |
||||
{ |
||||
$array | export-csv $txtBoxCSV.text |
||||
} |
||||
if ($chkBoxMail.Checked) |
||||
{ |
||||
$Date = Get-Date |
||||
$SubjectDate = "Exchange Message Tracking " + $Date.Tostring('HH:mm-MM.dd.yyyy') |
||||
send-mailmessage -to $txtBoxToMail.text -from $txtBoxFromMail.text -subject $SubjectDate -body "Attached is the message tracking" -Attachments 'MessageTrackingGUI.log' -BodyAsHTML -SmtpServer $txtBoxMail.text |
||||
} |
||||
$formTrackLog.refresh() |
||||
} else { |
||||
write-host "No results found!" -ForegroundColor white -BackgroundColor Red |
||||
} |
||||
} |
||||
|
||||
|
||||
$handler_comboBoxEventID_SelectedIndexChanged= |
||||
{ |
||||
# Get the Event ID when item is selected |
||||
$Global:ChoiceEventID = $comboBoxEventID.selectedItem.ToString() |
||||
} |
||||
|
||||
$OnLoadForm_StateCorrection= |
||||
{#Correct the initial state of the form to prevent the .Net maximized form issue |
||||
$formTrackLog.WindowState = $InitialFormWindowState |
||||
} |
||||
|
||||
#---------------------------------------------- |
||||
#region Generated Form Code |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 550 |
||||
$System_Drawing_Size.Width = 1000 |
||||
$formTrackLog.ClientSize = $System_Drawing_Size |
||||
$formTrackLog.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$formTrackLog.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0) |
||||
$formTrackLog.Name = "formTrackLog" |
||||
$formTrackLog.Text = "Message Tracking Log GUI - By Nicolas PRIGENT [www.get-cmd.com]" |
||||
$formTrackLog.add_Load($handler_formTrackLog_Load) |
||||
|
||||
$labEventID.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 570 |
||||
$System_Drawing_Point.Y = 5 |
||||
$labEventID.Location = $System_Drawing_Point |
||||
$labEventID.Name = "labEventID" |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 23 |
||||
$System_Drawing_Size.Width = 60 |
||||
$labEventID.Size = $System_Drawing_Size |
||||
$labEventID.TabIndex = 18 |
||||
$labEventID.Text = "Event ID:" |
||||
$labEventID.add_Click($handler_labEventID_Click) |
||||
|
||||
$formTrackLog.Controls.Add($labEventID) |
||||
|
||||
$comboBoxEventID.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$comboBoxEventID.FormattingEnabled = $True |
||||
$comboBoxEventID.Items.Add("")|Out-Null |
||||
$comboBoxEventID.Items.Add("SEND")|Out-Null |
||||
$comboBoxEventID.Items.Add("DELIVER")|Out-Null |
||||
$comboBoxEventID.Items.Add("RECEIVE")|Out-Null |
||||
$comboBoxEventID.Items.Add("FAIL")|Out-Null |
||||
$comboBoxEventID.Items.Add("DSN")|Out-Null |
||||
$comboBoxEventID.Items.Add("RESOLVE")|Out-Null |
||||
$comboBoxEventID.Items.Add("EXPAND")|Out-Null |
||||
$comboBoxEventID.Items.Add("REDIRECT")|Out-Null |
||||
$comboBoxEventID.Items.Add("TRANSFER")|Out-Null |
||||
$comboBoxEventID.Items.Add("SUBMIT")|Out-Null |
||||
$comboBoxEventID.Items.Add("POISONMESSAGE")|Out-Null |
||||
$comboBoxEventID.Items.Add("DEFER")|Out-Null |
||||
$System_Drawing_PointComboEVentID = New-Object System.Drawing.Point |
||||
$System_Drawing_PointComboEVentID.X = 630 |
||||
$System_Drawing_PointComboEVentID.Y = 3 |
||||
$comboBoxEventID.Location = $System_Drawing_PointComboEVentID |
||||
$comboBoxEventID.Name = "comboBoxEventID" |
||||
$System_Drawing_SizeComboEVentID = New-Object System.Drawing.Size |
||||
$System_Drawing_SizeComboEVentID.Height = 21 |
||||
$System_Drawing_SizeComboEVentID.Width = 121 |
||||
$comboBoxEventID.Size = $System_Drawing_SizeComboEVentID |
||||
$comboBoxEventID.TabIndex = 17 |
||||
$comboBoxEventID.add_SelectedIndexChanged($handler_comboBoxEventID_SelectedIndexChanged) |
||||
$formTrackLog.Controls.Add($comboBoxEventID) |
||||
|
||||
$labEndDate.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 300 |
||||
$System_Drawing_Point.Y = 33 |
||||
$labEndDate.Location = $System_Drawing_Point |
||||
$labEndDate.Name = "labEndDate" |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 20 |
||||
$System_Drawing_Size.Width = 54 |
||||
$labEndDate.Size = $System_Drawing_Size |
||||
$labEndDate.TabIndex = 12 |
||||
$labEndDate.Text = "End" |
||||
|
||||
$formTrackLog.Controls.Add($labEndDate) |
||||
|
||||
$labStartDate.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
|
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 300 |
||||
$System_Drawing_Point.Y = 5 |
||||
$labStartDate.Location = $System_Drawing_Point |
||||
$labStartDate.Name = "labStartDate" |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 20 |
||||
$System_Drawing_Size.Width = 54 |
||||
$labStartDate.Size = $System_Drawing_Size |
||||
$labStartDate.TabIndex = 11 |
||||
$labStartDate.Text = "Start" |
||||
$labStartDate.add_Click($handler_labStartDate_Click) |
||||
|
||||
$formTrackLog.Controls.Add($labStartDate) |
||||
|
||||
$dgResults.AllowSorting = $true |
||||
$dgResults.Anchor = 15 |
||||
$dgResults.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$dgResults.DataMember = "" |
||||
$dgResults.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0) |
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 9 |
||||
$System_Drawing_Point.Y = 108 |
||||
$dgResults.Location = $System_Drawing_Point |
||||
$dgResults.Name = "dgResults" |
||||
$dgResults.PreferredColumnWidth = 200 |
||||
$dgResults.ReadOnly = $True |
||||
$dgResults.RowHeadersVisible = $false |
||||
$dgResults.RowHeaderWidth = 60 |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 500 |
||||
$System_Drawing_Size.Width = 990 |
||||
$dgResults.Size = $System_Drawing_Size |
||||
$dgResults.TabIndex = 9 |
||||
$dgResults.add_Navigate($handler_dgResults_Navigate) |
||||
|
||||
$formTrackLog.Controls.Add($dgResults) |
||||
|
||||
$dateTimePickerEnd.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 360 |
||||
$System_Drawing_Point.Y = 33 |
||||
$dateTimePickerEnd.Location = $System_Drawing_Point |
||||
$dateTimePickerEnd.Name = "dateTimePicker2" |
||||
$System_Drawing_SizeEnd = New-Object System.Drawing.Size |
||||
$System_Drawing_SizeEnd.Height = 20 |
||||
$System_Drawing_SizeEnd.Width = 200 |
||||
$dateTimePickerEnd.Size = $System_Drawing_SizeEnd |
||||
$dateTimePickerEnd.TabIndex = 8 |
||||
|
||||
$formTrackLog.Controls.Add($dateTimePickerEnd) |
||||
|
||||
$dateTimePickerStart.CustomFormat = "MM/DD/YYYY 00:00:01" |
||||
$dateTimePickerStart.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 360 |
||||
$System_Drawing_Point.Y = 3 |
||||
$dateTimePickerStart.Location = $System_Drawing_Point |
||||
$dateTimePickerStart.Name = "dateTimePicker1" |
||||
$System_Drawing_SizeStart = New-Object System.Drawing.Size |
||||
$System_Drawing_SizeStart.Height = 20 |
||||
$System_Drawing_SizeStart.Width = 200 |
||||
$dateTimePickerStart.Size = $System_Drawing_SizeStart |
||||
$dateTimePickerStart.TabIndex = 7 |
||||
|
||||
$formTrackLog.Controls.Add($dateTimePickerStart) |
||||
|
||||
$txtBoxRecipients.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 40 |
||||
$System_Drawing_Point.Y = 30 |
||||
$txtBoxRecipients.Location = $System_Drawing_Point |
||||
$txtBoxRecipients.Name = "txtBoxRecipients" |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 20 |
||||
$System_Drawing_Size.Width = 250 |
||||
$txtBoxRecipients.Size = $System_Drawing_Size |
||||
$txtBoxRecipients.TabIndex = 4 |
||||
$txtBoxRecipients.Text = "" |
||||
$formTrackLog.Controls.Add($txtBoxRecipients) |
||||
|
||||
$txtBoxSubject.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 65 |
||||
$System_Drawing_Point.Y = 65 |
||||
$txtBoxSubject.Location = $System_Drawing_Point |
||||
$txtBoxSubject.Name = "txtBoxSubject" |
||||
$System_Drawing_SizeSubject = New-Object System.Drawing.Size |
||||
$System_Drawing_SizeSubject.Height = 20 |
||||
$System_Drawing_SizeSubject.Width = 495 |
||||
$txtBoxSubject.Size = $System_Drawing_SizeSubject |
||||
$txtBoxSubject.TabIndex = 4 |
||||
$txtBoxSubject.Text = "" |
||||
$formTrackLog.Controls.Add($txtBoxSubject) |
||||
|
||||
$txtBoxSenders.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 40 |
||||
$System_Drawing_Point.Y = 3 |
||||
$txtBoxSenders.Location = $System_Drawing_Point |
||||
$txtBoxSenders.Name = "txtBoxSenders" |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 20 |
||||
$System_Drawing_Size.Width = 250 |
||||
$txtBoxSenders.Size = $System_Drawing_Size |
||||
$txtBoxSenders.TabIndex = 3 |
||||
$txtBoxSenders.Text = "" |
||||
$formTrackLog.Controls.Add($txtBoxSenders) |
||||
|
||||
$buttonGo.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$buttonGo.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0) |
||||
|
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 755 |
||||
$System_Drawing_Point.Y = 3 |
||||
$buttonGo.Location = $System_Drawing_Point |
||||
$buttonGo.Name = "button1" |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 25 |
||||
$System_Drawing_Size.Width = 240 |
||||
$buttonGo.Size = $System_Drawing_Size |
||||
$buttonGo.TabIndex = 1 |
||||
$buttonGo.Text = ">>> Run <<<" |
||||
$buttonGo.UseVisualStyleBackColor = $True |
||||
$buttonGo.add_Click($processData) |
||||
|
||||
$formTrackLog.Controls.Add($buttonGo) |
||||
|
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 3 |
||||
$System_Drawing_Point.Y = 5 |
||||
$labFrom.Location = $System_Drawing_Point |
||||
$labFrom.Name = "labFrom" |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 20 |
||||
$System_Drawing_Size.Width = 54 |
||||
$labFrom.Size = $System_Drawing_Size |
||||
$labFrom.TabIndex = 11 |
||||
$labFrom.Text = "From:" |
||||
|
||||
$formTrackLog.Controls.Add($labFrom) |
||||
|
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 3 |
||||
$System_Drawing_Point.Y = 32 |
||||
$labTo.Location = $System_Drawing_Point |
||||
$labTo.Name = "labTo" |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 20 |
||||
$System_Drawing_Size.Width = 54 |
||||
$labTo.Size = $System_Drawing_Size |
||||
$labTo.TabIndex = 11 |
||||
$labTo.Text = "To:" |
||||
$formTrackLog.Controls.Add($labTo) |
||||
|
||||
$System_Drawing_Point = New-Object System.Drawing.Point |
||||
$System_Drawing_Point.X = 3 |
||||
$System_Drawing_Point.Y = 67 |
||||
$labSubject.Location = $System_Drawing_Point |
||||
$labSubject.Name = "labSubject" |
||||
$System_Drawing_Size = New-Object System.Drawing.Size |
||||
$System_Drawing_Size.Height = 20 |
||||
$System_Drawing_Size.Width = 54 |
||||
$labSubject.Size = $System_Drawing_Size |
||||
$labSubject.TabIndex = 11 |
||||
$labSubject.Text = "Subject:" |
||||
$formTrackLog.Controls.Add($labSubject) |
||||
|
||||
$System_Drawing_SizeCSV = New-Object System.Drawing.Size |
||||
$System_Drawing_SizeCSV.Width = 84 |
||||
$System_Drawing_SizeCSV.Height = 24 |
||||
$chkBoxCSV.Size = $System_Drawing_SizeCSV |
||||
$chkBoxCSV.TabIndex = 1 |
||||
$chkBoxCSV.Text = "Export CSV" |
||||
$System_Drawing_PointCSV = New-Object System.Drawing.Point |
||||
$System_Drawing_PointCSV.X = 570 |
||||
$System_Drawing_PointCSV.Y = 64 |
||||
$chkBoxCSV.Location = $System_Drawing_PointCSV |
||||
$chkBoxCSV.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$chkBoxCSV.Name = "chkBoxCSV" |
||||
$formTrackLog.Controls.Add($chkBoxCSV) |
||||
|
||||
$System_Drawing_SizeMail = New-Object System.Drawing.Size |
||||
$System_Drawing_SizeMail.Width = 90 |
||||
$System_Drawing_SizeMail.Height = 24 |
||||
$chkBoxMail.Size = $System_Drawing_SizeMail |
||||
$chkBoxMail.TabIndex = 1 |
||||
$chkBoxMail.Text = "Send by mail" |
||||
$System_Drawing_PointMail = New-Object System.Drawing.Point |
||||
$System_Drawing_PointMail.X = 570 |
||||
$System_Drawing_PointMail.Y = 34 |
||||
$chkBoxMail.Location = $System_Drawing_PointMail |
||||
$chkBoxMail.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$chkBoxMail.Name = "chkBoxMail" |
||||
$formTrackLog.Controls.Add($chkBoxMail) |
||||
|
||||
$txtBoxMail.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_PointMail = New-Object System.Drawing.Point |
||||
$System_Drawing_PointMail.X = 660 |
||||
$System_Drawing_PointMail.Y = 34 |
||||
$txtBoxMail.Location = $System_Drawing_PointMail |
||||
$txtBoxMail.Name = "txtBoxMail" |
||||
$System_Drawing_SizeMail = New-Object System.Drawing.Size |
||||
$System_Drawing_SizeMail.Height = 20 |
||||
$System_Drawing_SizeMail.Width = 110 |
||||
$txtBoxMail.Size = $System_Drawing_SizeMail |
||||
$txtBoxMail.TabIndex = 3 |
||||
$txtBoxMail.Text = "SMTP Server" |
||||
$formTrackLog.Controls.Add($txtBoxMail) |
||||
|
||||
$txtBoxFromMail.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_PointFromMail = New-Object System.Drawing.Point |
||||
$System_Drawing_PointFromMail.X = 775 |
||||
$System_Drawing_PointFromMail.Y = 34 |
||||
$txtBoxFromMail.Location = $System_Drawing_PointFromMail |
||||
$txtBoxFromMail.Name = "txtBoxFromMail" |
||||
$System_Drawing_SizeFromMail = New-Object System.Drawing.Size |
||||
$System_Drawing_SizeFromMail.Height = 20 |
||||
$System_Drawing_SizeFromMail.Width = 110 |
||||
$txtBoxFromMail.Size = $System_Drawing_SizeFromMail |
||||
$txtBoxFromMail.TabIndex = 3 |
||||
$txtBoxFromMail.Text = "From" |
||||
$formTrackLog.Controls.Add($txtBoxFromMail) |
||||
|
||||
$txtBoxToMail.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_PointToMail = New-Object System.Drawing.Point |
||||
$System_Drawing_PointToMail.X = 890 |
||||
$System_Drawing_PointToMail.Y = 34 |
||||
$txtBoxToMail.Location = $System_Drawing_PointToMail |
||||
$txtBoxToMail.Name = "txtBoxToMail" |
||||
$System_Drawing_SizeToMail = New-Object System.Drawing.Size |
||||
$System_Drawing_SizeToMail.Height = 20 |
||||
$System_Drawing_SizeToMail.Width = 110 |
||||
$txtBoxToMail.Size = $System_Drawing_SizeToMail |
||||
$txtBoxToMail.TabIndex = 3 |
||||
$txtBoxToMail.Text = "To" |
||||
$formTrackLog.Controls.Add($txtBoxToMail) |
||||
|
||||
$txtBoxCSV.DataBindings.DefaultDataSourceUpdateMode = 0 |
||||
$System_Drawing_PointTXTCSV = New-Object System.Drawing.Point |
||||
$System_Drawing_PointTXTCSV.X = 660 |
||||
$System_Drawing_PointTXTCSV.Y = 65 |
||||
$txtBoxCSV.Location = $System_Drawing_PointTXTCSV |
||||
$txtBoxCSV.Name = "txtBoxCSV" |
||||
$System_Drawing_SizeTXTCSV = New-Object System.Drawing.Size |
||||
$System_Drawing_SizeTXTCSV.Height = 20 |
||||
$System_Drawing_SizeTXTCSV.Width = 250 |
||||
$txtBoxCSV.Size = $System_Drawing_SizeTXTCSV |
||||
$txtBoxCSV.TabIndex = 3 |
||||
$txtBoxCSV.Text = "Path to csv file" |
||||
$formTrackLog.Controls.Add($txtBoxCSV) |
||||
|
||||
|
||||
#endregion Generated Form Code |
||||
|
||||
#Save the initial state of the form |
||||
$InitialFormWindowState = $formTrackLog.WindowState |
||||
#Init the OnLoad event to correct the initial state of the form |
||||
$formTrackLog.add_Load($OnLoadForm_StateCorrection) |
||||
#Show the Form |
||||
$formTrackLog.ShowDialog()| Out-Null |
||||
|
||||
} #End Function |
||||
|
||||
#Call the Function |
||||
GenerateForm |
@ -0,0 +1,252 @@
@@ -0,0 +1,252 @@
|
||||
<# |
||||
.SYNOPSIS |
||||
Configures IIS log file settings |
||||
|
||||
Thomas Stensitzki |
||||
|
||||
THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE |
||||
RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. |
||||
|
||||
Version 1.1, 2016-07-28 |
||||
|
||||
Ideas, comments and suggestions to support@granikos.eu |
||||
|
||||
Some parts (c) Michel de Rooij, michel@eightwone.com |
||||
|
||||
.LINK |
||||
http://www.granikos.eu/en/scripts |
||||
|
||||
|
||||
.DESCRIPTION |
||||
This script reconfigures the IIS log folder to target a different folder besides the |
||||
default C:\inetpub\logs folder. Additionally the log settings can be adjusted as well. |
||||
The script changes the default log file location and settings on a server level. By |
||||
default the settings are inherited by websites. If manual changes have been made on |
||||
a webite level, not all settings will be inherited. |
||||
|
||||
.NOTES |
||||
Requirements |
||||
- Windows Server 2008 R2 SP1, Windows Server 2012 or Windows Server 2012 R2 |
||||
|
||||
|
||||
Revision History |
||||
-------------------------------------------------------------------------------- |
||||
1.0 Initial community release |
||||
1.1 PowerShell hygiene applied, some typo fixes |
||||
|
||||
|
||||
.PARAMETER LogFolderPath |
||||
New IIS log folder path, i.e. D:\IISLogs. Default is an empty string. |
||||
|
||||
.PARAMETER LogFilePeriod |
||||
Log file period (interval), Hourly|Daily|Weekly|Monthly|MaxSize |
||||
MaxSize configuration not yet implemented |
||||
|
||||
.PARAMETER LocalTimeRollover |
||||
Boolean parameter indicating, if the local time shall be used for filenames and rollover |
||||
Default $FALSE |
||||
|
||||
.EXAMPLE |
||||
Change the IIS log file location to D:\IISLogs |
||||
.\Set-Webserver.ps1 -LogFolderPath D:\IISLogs |
||||
|
||||
.EXAMPLE |
||||
Change the IIS log period to an hourly period |
||||
.\Set-Webserver.ps1 -LogFilePeriod Hourly |
||||
|
||||
.EXAMPLE |
||||
Use the local time for filenames and log file rollover |
||||
.\Set-Webserver.ps1 -LocalTimeRollover $true |
||||
|
||||
#> |
||||
|
||||
|
||||
Param( |
||||
[parameter(Position=0,Mandatory=$false,ValueFromPipeline=$false,HelpMessage='New IIS log folder path, i.e. D:\IISLogs')] |
||||
[string]$LogFolderPath = '', |
||||
[parameter(Position=1,Mandatory=$false,ValueFromPipeline=$false,HelpMessage='Log file period (Hourly|Daily|Weekly|Monthly|MaxSize)')] |
||||
[string]$LogFilePeriod = '', |
||||
[parameter(Position=2,Mandatory=$false,ValueFromPipeline=$false,HelpMessage='$true/$false indicating, if the local time shall be used for filenames and rollover')] |
||||
[bool]$LocalTimeRollover=$false |
||||
) |
||||
|
||||
process{ |
||||
|
||||
# log file property settings |
||||
$lfpDirectory = 'directory' |
||||
$lfpPeriod = 'period' |
||||
$lfpLocalTimeRollover = 'localTimeRollover' |
||||
|
||||
# Check if folder exists, otherwise create folder |
||||
function Create-Folder |
||||
{ |
||||
param |
||||
( |
||||
[string] |
||||
$folderPath |
||||
) |
||||
|
||||
Write-Verbose "Evaluating IIS folder path: $folderPath" |
||||
|
||||
if(-not ($folderPath -eq '')) |
||||
{ |
||||
if(-not (Test-Path $folderPath)) |
||||
{ |
||||
Write-Host "Creating IIS log folder path: $folderPath" |
||||
|
||||
New-Item -Path $folderPath -ItemType directory | Out-Null |
||||
} |
||||
else |
||||
{ |
||||
Write-Host "Folder $folderPath already exsists" |
||||
} |
||||
} |
||||
} |
||||
|
||||
# Change IIS log file setting |
||||
function ChangeIisLogSetting |
||||
{ |
||||
param |
||||
( |
||||
[string] |
||||
$settingName, |
||||
|
||||
[string] |
||||
$settingValue |
||||
) |
||||
|
||||
try |
||||
{ |
||||
Write-Verbose "Configuring IIS log setting $settingsName to value $settingsValue" |
||||
|
||||
$logConfig = @{$settingName=$settingValue} |
||||
|
||||
Set-WebConfigurationProperty 'system.applicationHost/sites/siteDefaults' -Name logFile -Value $logConfig |
||||
} |
||||
catch [system.exception] |
||||
{ |
||||
Write-Host 'An error occured while trying to write IIS settings. Please check permissions of your account and ensure that PowerShell is running from an elevated prompt.' -ForegroundColor Red |
||||
} |
||||
} |
||||
|
||||
# Change IIS default log location and other IIS log settings |
||||
function ChangeIisLogPath |
||||
{ |
||||
param |
||||
( |
||||
[string] |
||||
$folderPath |
||||
) |
||||
|
||||
Write-Verbose "IIS Log Folder Path to configure: $folderPath" |
||||
Write-Host "Configuring IIS default log location to '$folderPath'" |
||||
|
||||
if(Test-Path $folderPath) |
||||
{ |
||||
ChangeIisLogSetting $lfpDirectory $folderPath |
||||
} |
||||
else |
||||
{ |
||||
Write-Host "New IIS log folder $folderPath does not exist. IIS log file folder configuration has not been changed" -ForegroundColor Red |
||||
} |
||||
} |
||||
|
||||
# Change IIS log period |
||||
function ChangeIisLogPeriod |
||||
{ |
||||
param |
||||
( |
||||
[string] |
||||
$logPeriod |
||||
) |
||||
|
||||
if($AllowedLogFilePeriod -contains $logPeriod) |
||||
{ |
||||
Write-Verbose "Changing IIS log periog to: $logPeriod" |
||||
|
||||
ChangeIisLogSetting $lfpPeriod $logPeriod |
||||
} |
||||
} |
||||
|
||||
# Change IIS LocalTimeRollover setting |
||||
function ChangeLocalTimeRollover |
||||
{ |
||||
param |
||||
( |
||||
[bool] |
||||
$logLocalTimeRollover |
||||
) |
||||
|
||||
Write-Verbose "Changing IIS log local time rollover to: $logLocalTimeRollover" |
||||
|
||||
ChangeIisLogSetting $lfpLocalTimeRollover $logLocalTimeRollover |
||||
} |
||||
|
||||
|
||||
function CheckWindowsFeature |
||||
{ |
||||
param |
||||
( |
||||
[string] |
||||
$MajorOSVersion |
||||
) |
||||
|
||||
$featureInstalled = $false |
||||
|
||||
If ($MajorOSVersion -eq '6.1') |
||||
{ |
||||
Import-Module ServerManager |
||||
If(!(Get-Module ServerManager)) |
||||
{ |
||||
Write-Error 'Problem loading ServerManager module' |
||||
Exit 'ServerManager module could not be loaded!' |
||||
} |
||||
} |
||||
|
||||
Write-Verbose "Checking, if Windows Feature 'Web-Server' is installed" |
||||
|
||||
$feature = Get-WindowsFeature Web-Server |
||||
$featureInstalled = [bool]($feature.Installed) |
||||
|
||||
Write-Verbose "Feature 'Web-Server' installed: $featureInstalled" |
||||
|
||||
return( $featureInstalled ) |
||||
} |
||||
|
||||
## Main |
||||
Write-Verbose 'Script started' |
||||
|
||||
$MajorOSVersion= [string](Get-WmiObject Win32_OperatingSystem | Select-Object Version | Select-Object @{n='Major';e={($_.Version.Split('.')[0]+'.'+$_.Version.Split('.')[1])}}).Major |
||||
$AllowedLogFilePeriod = @('Hourly','Daily','Weekly','Monthly') # MaxSize not yet implemented |
||||
|
||||
if( CheckWindowsFeature($MajorOSVersion) ) |
||||
{ |
||||
|
||||
Write-Verbose 'Configuring IIS log file settings' |
||||
|
||||
if($LogFolderPath -ne '') |
||||
{ |
||||
# Create IIS Log File Folder, independent from server role |
||||
Create-Folder $LogFolderPath |
||||
|
||||
#Change log file settings |
||||
ChangeIisLogPath $LogFolderPath $LogFilePeriod |
||||
} |
||||
|
||||
if($LogFilePeriod -ne '') |
||||
{ |
||||
ChangeIisLogPeriod $LogFilePeriod |
||||
} |
||||
|
||||
if($LocalTimeRollover -ne $null) |
||||
{ |
||||
ChangeLocalTimeRollover $LocalTimeRollover |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
Write-Host 'IIS is currently not installed. Either add the windows feature manually or install Exchange first and adjust the IIS log file location afterwards.' -ForegroundColor Red |
||||
} |
||||
|
||||
Write-Verbose 'Script ended' |
||||
} #Process |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
|
||||
. 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1' |
||||
Connect-ExchangeServer -auto |
||||
|
||||
$LogFile="C:\add_ad_user_mail-$((Get-Date).ToString('yyyy-MM-dd')).log" |
||||
Start-Transcript -path $LogFile -append |
||||
|
||||
Write-Output "[$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fZ'))] [Start]" |
||||
|
||||
Import-module activedirectory |
||||
# $since=(Get-Date).AddDays(-4).ToUniversalTime().ToString('yyyyMMddHHmmss.fZ') |
||||
$since=(Get-Date).AddMinutes(-20).ToUniversalTime().ToString('yyyyMMddHHmmss.fZ') |
||||
$users=Get-ADUser -LDAPfilter "(&(objectCategory=person)(objectClass=user)(Name=*)(!(!UserPrincipalName=*))(whenCreated>=$since))" -searchBase 'CN=Users,DC=bloks,DC=local' |
||||
|
||||
foreach($user in $users) |
||||
{ |
||||
Write-Output "[$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fZ'))] [User] $($user.SamAccountName)" |
||||
if (Get-Mailbox -Identity $user.SamAccountName 2>$null) |
||||
{ |
||||
Write-Output "[$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fZ'))] [User] $($user.SamAccountName): It's alive" |
||||
} |
||||
else |
||||
{ |
||||
Write-Output "[$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fZ'))] [User] $($user.SamAccountName): enable mailbox" |
||||
Enable-Mailbox -Identity $user.SamAccountName |
||||
} |
||||
} |
||||
|
||||
Write-Output "[$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fZ'))] [End]" |
||||
|
||||
Stop-Transcript |
Loading…
Reference in new issue