-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEEDK_ps1_template.ps1
159 lines (118 loc) · 5.11 KB
/
EEDK_ps1_template.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Run script
# Return the status in CustomProps
# Steen Pedersen, 2022 - Version 005.1
# ------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------
#
# Preapare some environmental variables
$g_agentFound = $false
$g_agentNotFound_ExitCode = 100
$g_results =''
$g_temp_status_file = $env:temp+'\EEDK_PS1_Debug.log'
# Working directory
$g_working_dir = $PSScriptRoot
$g_ISO_Date_with_time = Get-Date -format "yyyy-MM-dd HH:mm:ss"
# Parameter help description
[Parameter(AttributeValues)]
[string]$PropNo
# ------------------------------------------------------------------------------------------------
function get_path_to_agent_tools()
{
# Find path to McAfee Agent
# Read information from 64 bit
if ((Get-WmiObject win32_operatingsystem | Select-Object osarchitecture).osarchitecture -like "64*")
{
#64bit code here
#Write-Output "64-bit OS"
Add-Content $g_temp_status_file "64-bit OS"
$Global:g_path_to_agent = (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Network Associates\ePolicy Orchestrator\Agent" -Name "Installed Path")."Installed Path"
}
else
{
#32bit code here
#Write-Output "32-bit OS"
Add-Content $g_temp_status_file "32-bit OS"
$Global:g_path_to_agent = (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent" -Name "Installed Path")."Installed Path"
}
$g_agentFound = Test-Path -Path ($Global:g_path_to_agent)
if ($g_agentFound)
{
$Global:g_Command_maconfig = [System.IO.Path]::Combine( [System.IO.Directory]::GetParent($Global:g_path_to_agent).FullName,"MACONFIG.EXE")
$Global:g_Command_cmdagent = [System.IO.Path]::Combine( [System.IO.Directory]::GetParent($Global:g_path_to_agent).FullName,"CMDAGENT.EXE")
}
else
{
$agent_error = [String]::Format("Error locating McAfee Agent... Exiting with Code {0}.", $g_agentNotFound_ExitCode)
Write-Host $agent_error -ForegroundColor Red
Exit $g_agentNotFound_ExitCode
}
}
function write_customprops()
{
param(
[string]$Value,
[string]$PropsNo
)
$Parms = [String]::Format("-custom -prop{0} ""{1}""", $PropsNo, $Value)
Add-Content $g_temp_status_file "Run $Global:g_Command_maconfig $Parms"
try {
$process_status = Start-Process $Global:g_Command_maconfig -ArgumentList $Parms -NoNewWindow -PassThru -Wait
Write-Host ([string]::Format("Executed successfully process: {0} with params: {1}",$Global:g_Command_maconfig,$Parms)) -ForegroundColor Green
}
catch {
"Error running $Global:g_Command_maconfig"
$cmd_exception =$_.Exception
$cmd_error = [String]::Format("Error running: {0} with Params: {1}, The following exception occured: {2}",$Global:g_Command_maconfig, $Parms, $cmd_exception)
Add-Content $g_temp_status_file $cmd_error
Write-Host $cmd_error -ForegroundColor Red
}
# Perform CMDAGENT.EXE -p = Collect and Send Props
$Parms = "-p"
Add-Content $g_temp_status_file "Run $Global:g_Command_cmdagent -p"
try {
$process_status = Start-Process $Global:g_Command_cmdagent -ArgumentList $Parms -NoNewWindow -PassThru -Wait
Write-Host ([string]::Format("Executed successfully process: {0} with params: {1}",$Global:g_Command_cmdagent,$Parms)) -ForegroundColor Green
}
catch {
"Error running $Global:g_Command_cmdagent"
$cmd_exception =$_.Exception
$cmd_error = [String]::Format("Error running: {0} with Params: {1}, The following exception occured: {2}",$Global:g_Command_cmdagent, $Parms, $cmd_exception)
Add-Content $g_temp_status_file $cmd_error
Write-Host $cmd_error -ForegroundColor Red
}
}
function return_results_to_ePO {
param(
[string]$PropsNo
)
write_customprops -PropsNo $PropsNo -Value $Global:g_results
"Status added to "+$g_temp_status_file
Add-Content $g_temp_status_file "$Global:g_results"
'Results: '+$Global:g_results
}
function place_your_code_here_function {
#
# Place your code here
#
# Set the value to be returned to ePO - max 255 char
$Global:g_results = "First test"
# Write the results to the Custom Props
# Maximum length of Custom Props is 255
# Setting the lenght to max 230 char before adding the date at the end.
$Global:g_results = $Global:g_results[0..230] -Join ""
$Global:g_results = $Global:g_results +", AT: "+$g_ISO_Date_with_time
}
################
# Main section #
################
function main()
{
# Write start time
Add-Content $g_temp_status_file ($g_ISO_Date_with_time+' Start :'+$PSCommandPath+$args)
get_path_to_agent_tools
place_your_code_here_function
return_results_to_ePO -PropsNo 8
#"Completed : "
#Get-Date -format "yyyyMMdd_HHmmss"
}
main