Last active
October 20, 2023 18:51
-
-
Save fortran01/fff22b3b45f142812e7dd7448a34bbfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Check if running as an administrator | |
# $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) | |
# $adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator | |
# if (-not ($currentUser.IsInRole($adminRole))) { | |
# Write-Error "You must run this script as an administrator because we need to set the trusted hosts list for WinRM." | |
# exit 1 | |
# } | |
# # Prompt for the Tidal workspace URL (e.g., https://workspace.tidal.cloud) | |
# $url = Read-Host -Prompt "Enter Tidal workspace URL (e.g., https://workspace.tidal.cloud)" | |
# # Prompt for the Tidal workspace username (e.g., user@email.com) | |
# $email = Read-Host -Prompt "Enter Tidal workspace username (e.g., user@email.com)" | |
# # Prompt for the Tidal workspace password | |
# $password = Read-Host -Prompt "Enter Tidal workspace password" -AsSecureString | |
# # Convert the password to plain text | |
# $passwordPlainText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) | |
# # Set the Tidal configuration values | |
# & tidal config set tidal.url $url | |
# & tidal config set tidal.email $email | |
# & tidal config set tidal.password $passwordPlainText | |
# # Verify API configuration | |
# & tidal doctor | |
# # Add all targets to the trusted hosts list | |
# Set-Item WSMan:localhost\client\trustedhosts -value * | |
# # Verify the value of the trusted hosts list | |
# Get-Item WSMan:localhost\client\trustedhosts | |
# # Prompt for the first IP address to write to C:\machine_stats\windows\servers.txt | |
# $ipAddress = Read-Host -Prompt "Enter the IP address of the first target host to test" | |
# # Write the IP address to C:\machine_stats\windows\servers.txt | |
# $ipAddress | Out-File -FilePath C:\machine_stats\windows\servers.txt | |
# # Write that we are about to prompt for the service account password to use to connect to the target hosts | |
# Write-Host "Enter the service account password to use to connect to the target hosts" | |
# cd to C:\machine_stats\windows | |
Set-Location C:\machine_stats\windows | |
# Run the powershell script C:\machine_stats\windows\save_password.ps1 | |
#& C:\machine_stats\windows\save_password.ps1 | |
# Prompt for the username of the service account to use to connect to the target hosts | |
$Username = Read-Host "Enter the username of the service account to use to connect to the target hosts" | |
# Execute the runner script for point-in-time collection and capture errors | |
#try { | |
# # Executing the script | |
# $output = .\runner.ps1 -UserName $Username 2>&1 | |
# # Pipe the output to the Tidal sync servers command | |
# $output2 = Write-Output $output | tidal sync servers 2>&1 | |
#} | |
#catch { | |
# Write-Error $_.Exception.Message | |
# exit 1 | |
#} | |
# Check if the output contains the error message | |
#if ($output -match '.*error.*' -or $output2 -match '.*wrong.*') { | |
# Write-Host "An error occurred, fix the error and try again:" -ForegroundColor Red | |
# Write-Host "$output" -ForegroundColor Red | |
# Write-Host "$output2" -ForegroundColor Red | |
#} | |
#else { | |
# Write-Host "Command executed successfully: $output" -ForegroundColor Green | |
#} | |
# Create the machine-stats wrapper script C:\machine_stats\windows\run_default.ps1 to run runner.ps1 | |
$Content = "C:\machine_stats\windows\runner.ps1 ``` | |
-UserName $Username ``` | |
-ServersPath `"C:\machine_stats\windows\servers.txt`" ``` | |
-ServerStatsPath `"C:\machine_stats\windows\server_stats.ps1`" ``` | |
-SecurePwdFilePath `"C:\machine_stats\windows\SecuredText.txt`" ``` | |
-CpuUtilizationTimeout 1 ``` | |
-CpuUtilizationOnlyValue ``` | |
-Measurements ``` | |
| tidal request -X POST /api/v1/measurements/import" | |
Set-Content -Path "C:\machine_stats\windows\run_default.ps1" -Value $Content | |
# Prompt for the username to use to run the scheduled task (defaults to tidal) | |
$Username = Read-Host "Enter the username to use to run the scheduled task (defaults to tidal)" | |
if ($Username -eq "") { | |
$Username = "tidal" | |
} | |
# Schedule run_default.ps1 to run every 5 minutes with HighestAvailable run level | |
# /rp allows this task to run whether the user is logged on or not | |
schtasks /create /tn "machine-stats1" /tr "powershell.exe -ExecutionPolicy Bypass -File C:\machine_stats\windows\run_default.ps1" /sc minute /mo 5 /ru $Username /rl highest /rp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very cool!