Skip to content

Instantly share code, notes, and snippets.

@dfinke
Created May 1, 2024 22:27
Show Gist options
  • Save dfinke/854b157505e1d954cf8c011e024a7fba to your computer and use it in GitHub Desktop.
Save dfinke/854b157505e1d954cf8c011e024a7fba to your computer and use it in GitHub Desktop.
# AI-enhanced PowerShell script using prompting for natural language and predictive insights
Import-Module PSAI
$assistant = New-OAIAssistant
# System Health Metrics
$metrics = @{
CPU = (Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples.CookedValue
Disk = (Get-WmiObject Win32_LogicalDisk | Measure-Object -Property FreeSpace -Average).Average
Memory = (Get-Counter '\Memory\% Committed Bytes In Use').CounterSamples.CookedValue
}
# Prompt for AI Assistant
$prompt = @"
Given the following system metrics:
CPU: $($metrics.CPU)
% Disk: $($metrics.Disk)
% Memory: $($metrics.Memory)%
Provide a summary of the system health and any recommendations if metrics are above normal.
"@
Invoke-SimpleQuestion -AssistantId $assistant.Id -Question $prompt
<#
Based on the given system metrics:
1. CPU: 9.53 - This metric denotes the CPU usage. A CPU usage of 9.53 is relatively low and is within normal range, indicating there is no heavy load on the processor.
2. % Disk: 304614998016 - This metric represents the disk utilization. Based on the values provided, the disk utilization seems unusually high. The value of 304614998016 may not directly reflect typical disk usage and might need further investigation.
3. % Memory: 69.29% - This metric shows the memory usage. A memory usage of 69.29% is moderately high but may remain within acceptable limits depending on the total amount of RAM available on the system.
Summary:
- The CPU usage is normal and doesn't indicate any immediate concerns.
- The disk utilization appears to be excessively high, possibly due to heavy disk I/O operations or other issues that require attention.
- The memory usage is somewhat high, but it might not be critical unless it keeps increasing.
Recommendations:
1. Investigate the abnormally high disk utilization to determine the cause, such as excessive read/write operations or inefficient disk usage by certain applications.
2. Monitor the memory usage trend over time to ensure it doesn't lead to performance degradation. Consider optimizing memory usage by closing unnecessary applications or processes.
3. Regularly monitor system metrics to detect any anomalies early on and address them promptly to maintain optimal system health and performance.
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment