Skip to content

Instantly share code, notes, and snippets.

using namespace System.Collections.Generic
using namespace System.Management.Automation
using namespace System.Security.AccessControl
using namespace Microsoft.Win32
function Get-InstalledSoftware {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
# Syntax:
# ?? -If $true -Then { 'yep' } -Else { 'nah' }
# ?? -If $true { 'yep' } : { 'nah' }
# ?? -If $true { 'yep' } else { 'nah' }
# ?? -If $true { 'yep' } { 'nah' }
#
# $true | ?? -Then { 'yep' } -Else { 'nah' }
# $true | ?? { 'yep' } : { 'nah' }
# $true | ?? { 'yep' } else { 'nah' }
# $true | ?? { 'yep' } { 'nah' }
@SeeminglyScience
SeeminglyScience / Enter-PSSessionWithEdit.ps1
Last active May 4, 2023 03:27
Proof of concept for "psedit" working outside of PSES.
function Enter-PSSessionWithEdit {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $ComputerName
)
end {
$enterEventName = 'RemoteSessionEditor.Enter'
if (-not $Host.Runspace.Events.GetEventSubscribers($enterEventName)) {
@SeeminglyScience
SeeminglyScience / gist:e8b0e1ef0673a288b7b67916e8303d99
Last active February 21, 2018 01:46
Working list of issues that can be closed after PSReadLine changes
PSReadLine
https://github.com/PowerShell/vscode-powershell/issues/535
https://github.com/PowerShell/vscode-powershell/issues/569
https://github.com/PowerShell/vscode-powershell/issues/1027
https://github.com/PowerShell/vscode-powershell/issues/815
https://github.com/PowerShell/vscode-powershell/issues/785
https://github.com/PowerShell/vscode-powershell/issues/550
https://github.com/PowerShell/vscode-powershell/issues/873
https://github.com/PowerShell/vscode-powershell/issues/998
@SeeminglyScience
SeeminglyScience / PlatformUnix.cs
Last active January 31, 2018 23:52
Unsuccessful proof of concept for fixing Unix Console.ReadKey without native binaries.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.PowerShell.Internal
{
internal class PlatformUnix
{
// termios
private const int STDIN_FILENO = 0; // File descriptor for Standard Input.
private const int NCCS = 64; // Size of the array c_cc for control characters.
@SeeminglyScience
SeeminglyScience / Get-ActiveTranscriptPath.ps1
Created November 22, 2017 22:21
Gets the path of active transcripts for the current runspace. Utilizes unsupported code, use at your own risk.
function Get-ActiveTranscriptPath {
[CmdletBinding()]
param()
end {
$flags = [System.Reflection.BindingFlags]'Instance, NonPublic'
$transcriptionData = $Host.Runspace.GetType().
GetProperty('TranscriptionData', $flags).
GetValue($Host.Runspace)
$transcripts = $transcriptionData.GetType().
@SeeminglyScience
SeeminglyScience / New-PowerShellApp.ps1
Created October 14, 2017 18:29
Very simple example of creating a silent executable that runs a PowerShell script
function New-PowerShellApp {
[CmdletBinding()]
param([string]$FilePath, [string]$Script)
end {
$Script = $Script -replace '"', '""'
Add-Type -OutputType WindowsApplication -OutputAssembly $FilePath -TypeDefinition @"
using System.Management.Automation;
namespace SilentPowerShell
$typeDefinition = @'
using System;
using System.Management.Automation;
using System.Reflection;
namespace PSStateTree.Commands
{
[OutputType(typeof(StateTreeInfo))]
[Cmdlet(VerbsCommon.Show, "PSStateTree")]
public class ShowPSStateTreeCommand : PSCmdlet
@SeeminglyScience
SeeminglyScience / PSReadlineCommandPalette.ps1
Last active July 31, 2017 02:52
POC VSCode style Command Palette for PSReadline
#requires -Version 5.1 -Module @{ModuleName = 'PSReadline'; RequiredVersion=1.2}
function Invoke-CommandPalette {
param(
[System.Nullable[System.ConsoleKeyInfo]] $key,
[object] $arg
)
end {
# Save the current buffer, cursor position, selection range and selection command count to
# be restored after the command is found.
# This should be included in SQL server if you have it installed, but I don't on this machine.
$package = Find-Package Microsoft.SqlServer.TransactSql.ScriptDom -Source https://www.nuget.org/api/v2
$package | Save-Package -Path $PWD
$fileBaseName = $package.Name + '.' + $package.Version
Rename-Item "$fileBaseName.nupkg" "$fileBaseName.zip"
Expand-Archive "$fileBaseName.zip"
Add-Type -Path $fileBaseName\lib\net40\Microsoft.SqlServer.TransactSql.ScriptDom.dll
# Example from https://docs.microsoft.com/en-us/sql/t-sql/queries/select-examples-transact-sql
$tSqlSample = @'