Skip to content

Instantly share code, notes, and snippets.

View SMSAgentSoftware's full-sized avatar

Trevor Jones SMSAgentSoftware

View GitHub Profile
@SMSAgentSoftware
SMSAgentSoftware / Invoke-AIChat.ps1
Last active March 18, 2025 14:56
PowerShell script to chat interactively with various AI models using their REST APIs. Requires API keys stored in an Azure KeyVault.
function Invoke-AIChat {
<#
.SYNOPSIS
Invokes an AI chat model to generate responses based on user prompts.
.DESCRIPTION
This function provides a unified interface to interact with various AI language model providers including:
- Azure OpenAI Services
- OpenAI API
- Anthropic Claude
@SMSAgentSoftware
SMSAgentSoftware / Invoke-GoogleAIChat.ps1
Created December 13, 2024 21:46
PowerShell function to interact with Google's Gemini AI models via the REST API. Requires the API key to be stored in an Azure KeyVault.
function Invoke-GoogleAIChat {
<#
.SYNOPSIS
PowerShell function for Google Chat API interaction via REST.
.DESCRIPTION
Provides a robust interface to Google Chat API with features including:
- Conversation history management
- Token usage tracking
- Markdown rendering support
@SMSAgentSoftware
SMSAgentSoftware / Invoke-OpenAIChat.ps1
Created December 13, 2024 20:09
PowerShell function to interact with OpenAI chat models via the REST API. Requires the API key stored in an Azure Keyvault.
function Invoke-OpenAIChat {
<#
.SYNOPSIS
PowerShell function for OpenAI Chat API interaction via REST.
.DESCRIPTION
Provides a robust interface to OpenAI Chat API with features including:
- Conversation history management
- Token usage tracking
- Markdown rendering support
@SMSAgentSoftware
SMSAgentSoftware / Invoke-AnthropicAIChat.ps1
Last active December 13, 2024 17:38
PowerShell function to interact with the Claude AI models via the Anthropic REST API. Requires the API key to be stored in an Azure KeyVault.
function Invoke-AnthropicAIChat {
<#
.SYNOPSIS
PowerShell function for Anthropic (Claude) AI Chat API interaction via REST.
.DESCRIPTION
Provides a robust interface to Anthropic (Claude) AI Chat API with features including:
- Conversation history management
- Token usage tracking
- Markdown rendering support
@SMSAgentSoftware
SMSAgentSoftware / Invoke-AzOpenAIChat.ps1
Last active December 13, 2024 19:06
PowerShell function for Azure OpenAI Chat API interaction via REST.
function Invoke-AzOpenAIChat {
<#
.SYNOPSIS
PowerShell function for Azure OpenAI Chat API interaction via REST.
.DESCRIPTION
Provides a robust interface to Azure OpenAI Chat API with features including:
- Conversation history management
- Token usage tracking
- Markdown rendering support
@SMSAgentSoftware
SMSAgentSoftware / Get-EntraAccessToken.ps1
Created December 5, 2024 16:07
PowerShell function providing a few options for obtaining an access token for Microsoft Entra
Function Get-EntraAccessToken {
[CmdletBinding(DefaultParameterSetName = 'Default')]
param (
[Parameter(ParameterSetName = "UseWAM")]
[Parameter(ParameterSetName = "GraphSDK")]
[Parameter(ParameterSetName = "ACRSClaim")]
[Parameter(ParameterSetName = "AzureIdentity")]
[Parameter(ParameterSetName = "Default")]
[string]
$ClientId = "14d82eec-204b-4c2f-b7e8-296a70dab67e", # Microsoft Graph PowerShell
@SMSAgentSoftware
SMSAgentSoftware / Get-EntraAccessTokenWithWAM.ps1
Created November 28, 2024 18:06
Example function for how to obtain an access token for Microsoft Entra using the Web Account Manager (WAM) broker in Windows
Function Get-EntraAccessTokenWithWAM {
[CmdletBinding()]
param (
[Parameter()]
[string]
$ClientId = "14d82eec-204b-4c2f-b7e8-296a70dab67e", # Microsoft Graph PowerShell
[Parameter()]
[string[]]
$Scopes = "https://graph.microsoft.com/.default",
[Parameter()]
@SMSAgentSoftware
SMSAgentSoftware / Activate-SecuredPIMRole.ps1
Last active January 28, 2025 00:49
An example of how to satisfy the conditional access policy requirement to activate a PIM role with the Microsoft PowerShell Graph SDK
# Use this code to retrieve all Conditional Access policies that use authentication context from Microsoft Graph
Connect-MgGraph
$policies = Get-MgIdentityConditionalAccessPolicy | Where-Object { $_.Conditions.Applications.IncludeAuthenticationContextClassReferences -ne $null }
$policies | ForEach-Object {
[PSCustomObject]@{
DisplayName = $_.DisplayName
State = $_.State
AuthContext = $_.Conditions.Applications.IncludeAuthenticationContextClassReferences
}
} | Format-Table -AutoSize
@SMSAgentSoftware
SMSAgentSoftware / LetsEatFluent.ps1
Created November 19, 2024 16:23
A simple WPF app example demonstrating the Fluent theme. Requires .Net 9 and PowerShell 7.5+
# Define the xaml code for the window
[xml]$xaml = @'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Let's Eat!"
ThemeMode="Dark"
SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" >
<Grid>
<TabControl Margin="5">
<TabItem>
@SMSAgentSoftware
SMSAgentSoftware / LetsEat.ps1
Created November 19, 2024 16:21
A simple WPF app example. Works with PowerShell 5+
# Define the xaml code for the window
[xml]$xaml = @'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Let's Eat!"
SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" >
<Grid>
<TabControl Margin="5">
<TabItem>
<TabItem.Header>