Skip to content

Instantly share code, notes, and snippets.

View PrateekKumarSingh's full-sized avatar

Prateek Singh PrateekKumarSingh

View GitHub Profile
# web search a keyword to get snippets
$Snippets = Search-Web "Jeffery Snover" |
ForEach-Object {$_.webpages.value.snippet}
# extract keywords from snippets
$Words = $snippets.ForEach({
Get-KeyPhrase -Text $_ -ErrorAction SilentlyContinue
}).documents.keyphrases.split(' ')
# add subscription keys & location from azure
# to $profile as $env variables
# and load them in them in current session
$null = New-LocalConfiguration -FromAzure -AddKeysToProfile -Verbose
# installation
Install-Module PSCognitiveService -Verbose -Force -Confirm:$false -Scope CurrentUser
# import module
Import-Module PSCognitiveService
# create cognitive service accounts in azure
$Params1 = @{
AccountType = 'Bing.Search.v7'
ResourceGroupName = 'demo-resource-group'
Import-Module Graphical
# inputs
$WarningPreference = 'SilentlyContinue'
$TimeGrain = [timespan]::FromMinutes(1)
$MetricName = 'Percentage CPU'
$ResourceName = 'MyVM'
$Start = [datetime]::Now.AddMinutes(-90)
$End = [datetime]::Now.AddMinutes(-45)
# plot the graph
Show-Graph -Datapoints $Datpoints -GraphTitle $MetricName -YAxisStep 5
Show-Graph -Datapoints $Datpoints -GraphTitle $MetricName -YAxisStep 5 -Type Line
Show-Graph -Datapoints $Datpoints -GraphTitle $MetricName -YAxisStep 5 -Type Scatter
# capture resource metrics
$ResourceID = (Get-AzResource -ResourceName $ResourceName).ResourceId
$Splat = @{
ResourceId = $ResourceID
MetricName = $MetricName
TimeGrain = $TimeGrain
StartTime = $Start
EndTime = $End
}
# inputs
$WarningPreference = 'SilentlyContinue'
$TimeGrain = [timespan]::FromMinutes(1)
$MetricName = 'Percentage CPU'
$ResourceName = 'MyVM'
$Start = [datetime]::Now.AddMinutes(-90)
$End = [datetime]::Now.AddMinutes(-45)
Application Performance Monitoring
1. response times, user satisfaction
2. delays is requests, most used
3. Windows Performance counters
4. capacity
4. logs
5. Alert
6. Action and remediation
7. dependencies
# Method 9 - From String using `-Match` operator
$Hashtable = @{}
@"
name=prateek
age=29
skills=powershell
"@ -split [System.Environment]::NewLine | ForEach-Object {
if ($_ -match '^(.*)=(.*)'){
$Hashtable[$matches[1]] = $matches[2]
}
# Method 8 - String to Hashtable using `ConvertFrom-StringData` cmdlet
@"
name=prateek
age=29
skills=powershell
"@ | ConvertFrom-StringData