Skip to content

Instantly share code, notes, and snippets.

@wyunchi-ms
wyunchi-ms / Remove-ProgressAction.ps1
Last active February 28, 2024 08:00
Remove the common parameter `ProgressAction` from help files
# modified from source: https://github.com/PowerShell/platyPS/issues/595#issuecomment-1820971702
function Remove-CommonParameterFromMarkdown {
<#
.SYNOPSIS
Remove a PlatyPS generated parameter block.
.DESCRIPTION
Removes parameter block for the provided parameter name from the markdown file provided.
#>
@wyunchi-ms
wyunchi-ms / Optimize-PowerShellScriptViaChatGPT.ps1
Created February 19, 2024 05:32
Optimize the powershell code leverage the power of ChatGPT
Param(
[Parameter(Mandatory=$true)]
[string]$PowerShellScriptPath,
[string]$ApiBase = (Get-Item Env:\AZURE_OPENAI_ENDPOINT).Value,
[string]$ApiKey = (Get-Item Env:\AZURE_OPENAI_API_KEY).Value,
[string]$ApiVersion = "2023-07-01-preview",
[string]$DeploymentId = "gpt-35-turbo-16k"
)
$Endpoint = "$ApiBase/openai/deployments/$DeploymentId/chat/completions?api-version=$ApiVersion"
@wyunchi-ms
wyunchi-ms / Optimize-MarkdownViaChatGPT.ps1
Created February 19, 2024 05:07
Optimize a markdown file leverage the power of ChatGPT
Param(
[Parameter(Mandatory=$true)]
[string]$MarkdownPath,
[string]$ApiBase = (Get-Item Env:\AZURE_OPENAI_ENDPOINT).Value,
[string]$ApiKey = (Get-Item Env:\AZURE_OPENAI_API_KEY).Value,
[string]$ApiVersion = "2023-07-01-preview",
[string]$DeploymentId = "gpt-35-turbo-16k"
)
$Endpoint = "$ApiBase/openai/deployments/$DeploymentId/chat/completions?api-version=$ApiVersion"
@wyunchi-ms
wyunchi-ms / Get-UnreferencedModules.ps1
Created February 19, 2024 05:02
Find the modules in PSGallery named as `Az.*` and owned by Azure PowerShell team but not referenced by AzPreview
$ModulesInPSGallery = Find-Module -Repository PSGallery -Name Az.* | Where-Object { $_.ProjectUri.AbsolutePath -eq "/Azure/azure-powershell" }
Import-LocalizedData -BindingVariable AzPreviewMetadata -BaseDirectory .\tools\AzPreview\ -FileName AzPreview.psd1
$ModulesReferencedByAzPreview = $AzPreviewMetadata.RequiredModules.ModuleName
$UnRefencedModules = @()
foreach ($module in $ModulesInPSGallery) {
if (-not $ModulesReferencedByAzPreview.Contains($module.Name)) {
$UnRefencedModules += $module
}
}
$UnRefencedModules | Format-Table
# Import目录下所有的psm1文件
function Import-Profile {
param(
[string]
$ProfileDirPath
)
$Profiles = Get-ChildItem -Recurse -Path $ProfileDirPath
foreach ($CustomProfile in $Profiles) {
Import-Module $CustomProfile
Write-Host "$($CustomProfile.Name) is loaded." -ForegroundColor Green
@wyunchi-ms
wyunchi-ms / Microsoft.Powershell_profile.ps1
Last active May 25, 2020 14:37
Common used powershell profile
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
Set-Alias -Name ll -Value Get-ChildItem
Set-Alias Open explorer.exe
function Update-PowershellProfile {
$GistURL = 'https://gist.githubusercontent.com/wyunchi-ms/bed4d69b122ccf5290fa31ae87e994e4/raw'
Invoke-WebRequest $GistURL -OutFile $Profile.CurrentUserCurrentHost -Headers @{"Cache-Control"="no-cache"}
@wyunchi-ms
wyunchi-ms / profiles.json
Created January 14, 2020 06:21
Terminal Config
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"globals" :
{
"alwaysShowTabs" : true,
"copyOnSelect" : true,
"defaultProfile" : "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"initialCols" : 120,
"initialRows" : 30,
"keybindings" :