-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathRunInfo.ps1
58 lines (48 loc) · 1.6 KB
/
RunInfo.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
# Author: Miodrag Milic <[email protected]>
# Last Change: 21-Sep-2016.
<#
.SYNOPSIS
Save run info to the file and exclude sensitive information.
.DESCRIPTION
Run this plugin as the last one to save all other info produced during the run.
To load it for inspection use `$info = Import-CliXml update_info.xml`.
#>
param(
$Info,
#Path to XML file to save
[string] $Path = 'update_info.xml',
#Match options with those words to erase
[string[]] $Exclude = @('password', 'apikey')
)
function deep_clone {
param($DeepCopyObject)
$memStream = new-object IO.MemoryStream
$formatter = new-object Runtime.Serialization.Formatters.Binary.BinaryFormatter
$formatter.Serialize($memStream,$DeepCopyObject)
$memStream.Position=0
$formatter.Deserialize($memStream)
}
# Runinfo must save its own run results directly in Info
function result($msg) { $Info.plugin_results.RunInfo += $msg; Write-Host $msg }
$Info.plugin_results.RunInfo = @()
$format = '{0,-15}{1}'
$orig_opts = $Info.Options
$opts = deep_clone $orig_opts
$excluded = ''
foreach ($w in $Exclude) {
foreach ($key in $Info.Options.Keys) {
if ($Info.Options.$key -is [HashTable]) {
foreach ($subkey in $Info.Options.$key.Keys) {
if ($subkey -like "*$w*") {
$excluded += "$key.$subkey "
$opts.$key.$subkey = '*****'
}
}
}
}
}
if ($excluded) { result ($format -f 'Excluded:', $excluded) }
result ($format -f 'File:', $Path)
$Info.Options = $opts
$Info | Export-CliXML $Path
$Info.Options = $orig_opts