Skip to content

Instantly share code, notes, and snippets.

View adamdriscoll's full-sized avatar
:bowtie:

Adam Driscoll adamdriscoll

:bowtie:
View GitHub Profile
@adamdriscoll
adamdriscoll / Out-UDGridView.Dashboard.ps1
Created April 10, 2018 18:30
Creates the dashboard used in Out-UDGridView
$Dashboard = New-UDDashboard -Title $Title -Content {
New-UDGrid -Headers $headers -Properties $Properties -Endpoint {
$FormattedItems | Out-UDGridData
}
}
Get-UDDashboard -Name "OutUDGridView" | Stop-UDDashboard
@adamdriscoll
adamdriscoll / performance-test.ps1
Created April 17, 2018 15:07
Using Scheduled endpoints and a cache rather than calling
$Schedule = New-UDEndpointSchedule -Every 1 -Second
$EverySecond = New-UDEndpoint -Schedule $Schedule -Endpoint {
$Cache:ModuleCount = (Get-Module -ListAvailable).Count
}
$moduleCount = New-UDEndpoint -Url "/moduleCount" -Endpoint {
(Get-Module -ListAvailable).Count
}
@adamdriscoll
adamdriscoll / Find-SqlModuleDashboard.ps1
Created April 20, 2018 04:01
Creates a dashboard that finds SQL PowerShell modules on the PowerShell Gallery
Import-Module UniversalDashboard
$Dashboard = New-UDDashboard -Title "SQL Modules" -Content {
New-UDTable -Title 'SQL Modules' -Headers @("Name", "Version", "Downloads") -Endpoint {
Find-Module *SQL* | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Version = $_.Version
Downloads = $_.AdditionalMetadata.downloadCount
}
@adamdriscoll
adamdriscoll / Find-SqlModuleDashboard.Scheduled.ps1
Created April 20, 2018 04:05
Finds schedule modules using a scheduled endpoint
Import-Module UniversalDashboard
$Schedule = New-UDEndpointSchedule -Every 10 -Minute
$Endpoint = New-UDEndpoint -Schedule $Schedule -Endpoint {
$Cache:Modules = Find-Module *SQL* | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Version = $_.Version
Downloads = $_.AdditionalMetadata.downloadCount
}
$Root = New-UDTreeNode -Name 'FileSystem' -Id 'FileSystem'
New-UDTreeView -Node $Root -OnNodeClicked {
param($Body)
$Obj = $Body | ConvertFrom-Json
if ($Obj.NodeId -eq 'FileSystem') {
Get-PSDrive -PSProvider FileSystem | ForEach-Object {
New-UDTreeNode -Name $_.Root -Id $_.Root
}
@adamdriscoll
adamdriscoll / CustomAction.ps1
Created August 18, 2018 20:38
Runs a custom action on install
New-Installer -ProductName "Notepad" -UpgradeCode c5b5bcbb-a94f-4490-9746-7563a454357f -OutputDirectory $PSScriptRoot -Content {
New-InstallerDirectory -PredefinedDirectoryName AppDataFolder -Content {
New-InstallerDirectory -DirectoryName "Notepad" -Content {
New-InstallerFile -Source (Join-Path $PSScriptRoot "notepad.ps1") -Id "Notepadps1"
}
}
} -CustomAction @(
New-InstallerCustomAction -FileId "Notepadps1" -RunOnInstall -CheckReturnValue
)
@adamdriscoll
adamdriscoll / influxdb.ps1
Created December 6, 2018 03:33
Example of InfluxDB integration into Universal Dashboard
Import-Module UniversalDashboard
Get-UDDashboard | Stop-UDDashboard
$EI = New-UDEndpointInitialization -Module (Join-Path $PSScriptRoot 'influxdb.psm1')
$Cache:NetworkStats = @(
'\network adapter(*)\bytes received/sec'
'\network adapter(*)\bytes sent/sec'
)
@adamdriscoll
adamdriscoll / influxdb.psm1
Created December 6, 2018 03:34
Function to retrieve data from InfluxDB from PowerShell
function Get-InfluxDb {
param(
[Parameter()]
$Url = 'http://localhost:8086/query?db=performance_data',
[Parameter()]
$Query
)
$Results = Invoke-RestMethod -Uri "$Url&q=$Query"
@adamdriscoll
adamdriscoll / extension.ts
Created December 22, 2018 10:01
Access VS Code's theme colors programmatically
import stripJsonComments = require('strip-json-comments');
var workbenchSettings = vscode.workspace.getConfiguration("workbench");
var theme = workbenchSettings.colorTheme;
var themePath = null;
var extension = vscode.extensions.all.find(x => {
var extensionTheme = x.packageJSON.contributes.themes && x.packageJSON.contributes.themes.find(y => {
return y.label === theme;
});
@adamdriscoll
adamdriscoll / viewmodel.ps1
Created January 8, 2019 05:26
Universal Dashboard view model support
Import-Module "F:\universal-dashboard\src\UniversalDashboard\bin\Debug\UniversalDashboard.Community.psd1"
$ViewModel = New-UDViewModel -Name "Home" -Members @{
Text = 1
Icon = 'user'
Click = New-UDEndpoint -Endpoint {
$this.Text++
$this.Icon = 'group'
}
Clear = New-UDEndpoint -Endpoint {
$this.Text = 0