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 / task.json
Created May 15, 2017 11:32
VSCode task.json to add a build command to package a PowerShell script as an exe
{
"version": "0.1.0",
"tasks": [
{
"taskName": "build",
"command": "powershell",
"args": ["Merge-Script -Script '${file}' -Bundle -OutputPath '${fileDirname}\\out' -OutputType Executable"],
"isBuildCommand": true,
"showOutput": "silent"
}
@adamdriscoll
adamdriscoll / Get-BoundParameter.ps1
Created July 25, 2017 15:01
PSeudoParameterBinding
function Get-BoundParameter {
param($commandAst)
$psuedoParameterBinderType = [System.Management.Automation.AliasInfo].Assembly.GetType('System.Management.Automation.Language.PseudoParameterBinder')
$bindingTypeType = [System.Management.Automation.AliasInfo].Assembly.GetType('System.Management.Automation.Language.PseudoParameterBinder+BindingType')
$psuedoParameterBinder = [Activator]::CreateInstance($psuedoParameterBinderType)
$DoPseudoParameterBinding = $psuedoParameterBinderType.GetMethod('DoPseudoParameterBinding', [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic)
$pseudoBindingInfoType = [System.Management.Automation.AliasInfo].Assembly.GetType('System.Management.Automation.Language.PseudoBindingInfo')
$bindingInfo = $DoPseudoParameterBinding.Invoke($psuedoParameterBinder, @($commandAst, $null, $null, $bindingTypeType.GetEnumValues()[0]))
@adamdriscoll
adamdriscoll / web.config
Created September 13, 2017 12:30
Universal Dashboard web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\net451\universaldashboard.exe" arguments="" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout" forwardWindowsAuthToken="false" />
@adamdriscoll
adamdriscoll / svg.ps1
Created January 22, 2018 12:06
Using SVG in UD
function New-Circle {
param($Color)
New-UDElement -Tag "svg" -Content {
New-UDElement -Tag "circle" -Attributes @{
cx = "50"
cy = "50"
r = "40"
stroke = "black"
strokeWidth = 1
@adamdriscoll
adamdriscoll / waxon.ps1
Created February 16, 2018 02:31
Real time updates using Set-UDElement and Get-UDElement
$dashboard = New-UDDashboard -Title "PowerShell Universal Dashboard" -Content {
New-UDRow -Columns {
New-UDColumn -Size 1 {
New-UDElement -Tag "input" -Attributes @{
type = "button"
value = "Click me!"
onClick = {
$Element = Get-UDElement -Id "textbox"
if ($Element.Content[0] -eq "Wax on") {
Set-UDElement -Id "textbox" -Content {
@adamdriscoll
adamdriscoll / progress.ps1
Created February 17, 2018 01:47
Create a progress bar with UD
$dashboard = New-UDDashboard -Title "PowerShell Universal Dashboard" -Content {
New-UDRow -Columns {
New-UDColumn -Size 1 {
New-UDElement -Tag "a" -Attributes @{
className = "btn"
onClick = {
$percent = 0
while($percent -le 100) {
Set-UDElement -Id "status" -Content {"$percent%"}
@adamdriscoll
adamdriscoll / MultiDataset.ps1
Created February 18, 2018 14:38
Multiple data sets for New-UDMonitor
$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDMonitor -Title "Monitor" -Id "Monitor" -ChartBackgroundColor @("#80962F23", "#8014558C") -ChartBorderColor @("#80962F23", "#8014558C") -Label @("Virutal Memory", "Physical Memory") -Type Line -EndPoint {
Out-UDMonitorData -Data @(
Get-Random
Get-Random
)
}
}
@adamdriscoll
adamdriscoll / Out-UDGridView.Example.ps1
Created April 10, 2018 18:13
Out-UDGridView example
Get-Process | Out-UDGridView
@adamdriscoll
adamdriscoll / Out-UDGridView.Formatting.ps1
Last active April 10, 2018 18:36
Formatting in Out-UDGridView
$FormatData = Get-FormatData -TypeName (Get-Process | Get-Member).TypeName
if ($FormatData -ne $null) {
$TableControl = $FormatData.FormatViewDefinition.Control | Where-Object { $_ -is [System.Management.Automation.TableControl] }
if ($TableControl -ne $null) {
$Row = $TableControl.Rows | Select-Object -First 1
$i = 0
foreach($Header in $TableControl.Headers) {
if ([String]::IsNullOrEmpty($Header.Label)) {
@adamdriscoll
adamdriscoll / Out-UDGridView.PortDetection.ps1
Created April 10, 2018 18:29
Out-UDGridView port detection
$Ports = Get-CimInstance -ClassName MSFT_NetTCPConnection -Namespace root\StandardCimv2 | Where-Object State -eq 'Listen'
$Port = 10000
foreach($Port in 10000..20000) {
if (($Ports.LocalPort | Where-Object { $_ -eq $Port } | Measure-Object).Count -eq 0)
{
break
}
}