@@ -34,14 +34,20 @@ The default value is 30.
3434
3535Capture point-in-time CPU utilization value rather than a peak and average over a given time.
3636
37+ . PARAMETER Measurements
38+
39+ Specifies if the data should be output in a structure that matches the TMP /measurements endpoint.
40+ This is intended to capture point-in-time CPU Utilization.
41+
3742. INPUTS
3843
3944None. You cannot pipe objects to runner.ps1
4045
4146. OUTPUTS
4247
43- runner.ps1 generates a JSON output with all the gathered data suitable to be
44- used with Tidal Tools or Tidal Migrations API.
48+ Default behaviour will output JSON which is suitable to pipe to the Tidal Tools command "tidal sync servers".
49+
50+ Adding the -Measurements flag will output JSON which is suitable to pipe to the Tidal Migrations Platform /measurements API endpoint.
4551
4652. EXAMPLE
4753
@@ -51,6 +57,8 @@ used with Tidal Tools or Tidal Migrations API.
5157
5258.\runner.ps1 -UserName myuser
5359
60+ .\runner.ps1 -UserName myuser -Measurements
61+
5462#>
5563[CmdletBinding ()]
5664param (
@@ -84,9 +92,19 @@ param (
8492
8593 [Parameter ()]
8694 [switch ]
87- $CpuUtilizationOnlyValue
95+ $CpuUtilizationOnlyValue ,
96+
97+ [Parameter ()]
98+ [switch ]
99+ $Measurements
88100)
89101
102+ # If the -Measurements flag is used, set -CPUUtilizationOnlyValue and -CPUUtilizationTimeout 1
103+ if ($Measurements ) {
104+ $CpuUtilizationOnlyValue = $true
105+ $CpuUtilizationTimeout = 1
106+ }
107+
90108if (! [System.IO.File ]::Exists($SecurePwdFilePath )) {
91109 Write-Error " $SecurePwdFilePath does not exist. Be sure to run save_password.ps1 before trying again."
92110 exit 1
@@ -98,7 +116,7 @@ $secPwd = Get-Content $SecurePwdFilePath | ConvertTo-SecureString
98116$cred = New-Object System.Management.Automation.PSCredential - ArgumentList $UserName , $secPwd
99117
100118try {
101- $env_user = Invoke-Command - ComputerName ([Environment ]::MachineName) - Credential $cred - ScriptBlock { $env: USERNAME } - ErrorAction Stop
119+ $env_user = Invoke-Command - ComputerName ([Environment ]::MachineName) - Credential $cred - ScriptBlock { $env: USERNAME } - ErrorAction Stop
102120 Write-Host " Executing inventory gathering as user: $env_user ..."
103121} catch [System.Management.Automation.Remoting.PSRemotingTransportException ] {
104122 Write-Host " Executing inventory gathering..."
@@ -122,15 +140,15 @@ $server_list | ForEach-Object {
122140 if ($NoWinRM ) {
123141 $startJobParams = @ {
124142 ScriptBlock = $ServerStats
125- ArgumentList = $_ , $cred , $ProcessStats , $CpuUtilizationTimeout , $CpuUtilizationOnlyValue , $NoWinRM
143+ ArgumentList = $_ , $cred , $ProcessStats , $CpuUtilizationTimeout , $CpuUtilizationOnlyValue , $NoWinRM , $Measurements
126144 }
127145 $jobs += Start-Job @startJobParams
128146 } else {
129147 $invokeCommandParams = @ {
130148 ComputerName = $_
131149 Credential = $cred
132150 ScriptBlock = $ServerStats
133- ArgumentList = " localhost" , $null , $ProcessStats , $CpuUtilizationTimeout , $CpuUtilizationOnlyValue , $NoWinRM
151+ ArgumentList = " localhost" , $null , $ProcessStats , $CpuUtilizationTimeout , $CpuUtilizationOnlyValue , $NoWinRM , $Measurements
134152 }
135153 $jobs += Invoke-Command @invokeCommandParams - AsJob
136154 }
@@ -155,14 +173,22 @@ Do {
155173} Until (($jobs | Get-Job | Where-Object { (($_.State -eq " Running" ) -or ($_.state -eq " NotStarted" )) }).count -eq 0 )
156174
157175$jobs | Receive-Job | ForEach-Object {
158- $server_stats += $_
176+ $server_stats += $_ | Select - Property * - ExcludeProperty PSComputerName , RunSpaceID , PSShowComputerName
159177}
160178
161179$num_results = $server_stats.Count
162180Write-Host " $num_results results received out of $num_servers servers."
163181
164- # Output results
165- $results = @ { servers = $server_stats }
182+ # # Build result
183+
184+ # Set root object key
185+ $root_object_key = " servers"
186+ if ($Measurements ) {
187+ $root_object_key = " measurements"
188+ }
189+
190+ # output result
191+ $results = @ { $root_object_key = $server_stats }
166192$json = $results | ConvertTo-Json - Depth 99
167193Write-Output $json
168194
0 commit comments