forked from StartAutomating/PSDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trace-ADOCommand.ps1
56 lines (53 loc) · 1.83 KB
/
Trace-ADOCommand.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
function Trace-ADOCommand
{
<#
.Synopsis
Traces information about commands run in Azure DevOps
.Description
Traces information a command line into the output of Azure DevOps.
.Example
Trace-ADOCommand -Command Get-Process -Parameter @{id=$pid}
.Example
$myInvocation | Trace-ADOCommand
.Link
Write-ADOCommand
.Link
https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "", Justification="Directly outputs in certain scenarios")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Test-ForUnusableFunction", "", Justification="Directly outputs in certain scenarios")]
[OutputType([string])]
param(
# The command line.
[Parameter(Mandatory,ParameterSetName='Command',ValueFromPipelineByPropertyName)]
[Alias('MyCommand','Line')]
[string]
$Command,
# A dictionary of parameters to the command.
[Parameter(ParameterSetName='Command',ValueFromPipelineByPropertyName)]
[Alias('Parameters', 'BoundParameters')]
[Collections.IDictionary]
$Parameter
)
process {
if ($Command) {
#region Write Command Message
$message = (
'##[command]' + $Command + ' ' + @(
if ($Parameter) {
foreach ($kv in $Parameter.GetEnumerator()) {
'-' + $kv.Key
$kv.Value
}
}
) -join ' '
)
if ($env:Agent_ID -and $DebugPreference -eq 'SilentlyContinue') {
Write-Host -Object $message
} else {
$message
}
#endregion Write Command Message
}
}
}