-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExternal_To_org.PS1
87 lines (78 loc) · 2.87 KB
/
External_To_org.PS1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Param(
[parameter(Mandatory=$false)]
[Bool]$AutoOpen,
[parameter(Mandatory=$false)]
[String]$OutFile,
[parameter(Mandatory=$false)]
[Bool]$IgnoreInParams,
[parameter(Mandatory=$false)]
[Bool]$IgnoreOutParams)
$Error.Clear()
$DefaultFolder=[Environment]::CurrentDirectory
$Destination = "3 Emails received from outside.CSV"
$Dire = "\..\Logs Mania\LOGS_DATA\"
$Destination = $DefaultFolder + $Dire + "\" + $Destination
if($OutFile -ne [String]::Empty)
{
$OutFileType = [System.IO.Path]::GetExtension($OutFile.ToUpper())
$OriginalFileType = [System.IO.Path]::GetExtension($Destination.ToUpper())
if($OutFileType -ne $OriginalFileType)
{
Write-Host "You have chosen" $OutFileType "as the output, but this script was originally generated as" $OriginalFileType -ForegroundColor Red
Write-Host "Either change -OutFile to" $OriginalFileType "or generate the script again with the output as" $OutFileType -ForegroundColor Red
Write-Host "You can also modify the OutputFormat variable in this script to match the correct Log Parser 2.2 COM output format." -ForegroundColor Red
[System.Environment]::NewLine
return
}
else
{
if($true -ne $OutFile.Contains("\"))
{
$Destination = $DefaultFolder + "\" + $OutFile
}
else
{
$Destination = $OutFile
}
}
}
$LogQuery = New-Object -ComObject "MSUtil.LogQuery"
$InputFormat = New-Object -ComObject "MSUtil.LogQuery.CSVInputFormat"
$OutputFormat = New-Object -ComObject "MSUtil.LogQuery.CSVOutputFormat"
if($IgnoreInParams-eq $false){
$InputFormat.headerRow=1
#$InputFormat.dQuotes=0 #deprecated try 'useDoubleQuotes' instead
$InputFormat.nFields=-1
$InputFormat.nSkipLines=4
$InputFormat.iTsFormat="yyyy-MM-dd hh:mm:ss"
$InputFormat.iCodePage=0
$InputFormat.fixedFields=1
$InputFormat.dtLines=10
}
if($IgnoreOutParams -eq $false){
$OutputFormat.Headers="AUTO"
$OutputFormat.oDQuotes="AUTO"
$OutputFormat.tabs=0
$OutputFormat.oTsFormat="yyyy-MM-dd hh:mm:ss"
$OutputFormat.oCodepage=0
$OutputFormat.fileMode=1
}
Write-Progress -Activity "Executing query, please wait..." -Status " "
$SQLQuery = "SELECT count (DISTINCT [message-id]) as orgID_Recived_outside_email INTO '" + $Destination + "' FROM '\Logs Mania\LOGS\*.LOG' WHERE ([sender-address] not LIKE '%org.com%' and [recipient-address] LIKE '%org.com%' AND [client-ip] IS NOT NULL)"
$rtnVal = $LogQuery.ExecuteBatch($SQLQuery, $InputFormat, $OutputFormat);
$OutputFormat = $null;
$InputFormat = $null;
$LogQuery = $null;
if($AutoOpen)
{
try
{
Start-Process($Destination)
}
catch
{
Write-Host $_.Exception.Message -ForegroundColor Red
Write-Host $_.Exception.GetType().FullName -ForegroundColor Red
Write-Host "NOTE: No output file will be created if the query returned zero records!" -ForegroundColor Gray
}
}