From 1c4e9feb1fdde567e8b9a163b8c38c791b330a9d Mon Sep 17 00:00:00 2001 From: Gal Szkolnik Date: Tue, 30 Nov 2021 22:04:04 -0500 Subject: [PATCH] Stuff Invoke-XApp (untested) Find-MTU (grabbed from web) Get-FreeDiskSpace (Wmi based) WinCreds package Generate-FancyZones for FancyZones PowerToy --- WinCreds/Get-CredentialEntryTitle.ps1 | 13 +++ WinCreds/Remove-CredentialEntry.ps1 | 26 +++++ WinCreds/_.package.json | Bin 0 -> 1274 bytes base.win/Generate-FancyZones.ps1 | 155 ++++++++++++++++++++++++++ base/Find-MTU.ps1 | 69 ++++++++++++ base/Get-FreeDiskSpace.ps1 | 1 + xserver/Invoke-XApp.ps1 | 107 ++++++++++++++++++ xserver/_.package.json | Bin 0 -> 1116 bytes 8 files changed, 371 insertions(+) create mode 100644 WinCreds/Get-CredentialEntryTitle.ps1 create mode 100644 WinCreds/Remove-CredentialEntry.ps1 create mode 100644 WinCreds/_.package.json create mode 100644 base.win/Generate-FancyZones.ps1 create mode 100644 base/Find-MTU.ps1 create mode 100644 base/Get-FreeDiskSpace.ps1 create mode 100644 xserver/Invoke-XApp.ps1 create mode 100644 xserver/_.package.json diff --git a/WinCreds/Get-CredentialEntryTitle.ps1 b/WinCreds/Get-CredentialEntryTitle.ps1 new file mode 100644 index 0000000..ae1dead --- /dev/null +++ b/WinCreds/Get-CredentialEntryTitle.ps1 @@ -0,0 +1,13 @@ +[CmdletBinding()] param ( + [string]$Pattern +) + +begin { +} + +process { + cmdkey /list | Where-Object { $_ -like "*Target:*" -and $_ -like "$Pattern" } +} + +end { +} \ No newline at end of file diff --git a/WinCreds/Remove-CredentialEntry.ps1 b/WinCreds/Remove-CredentialEntry.ps1 new file mode 100644 index 0000000..720da39 --- /dev/null +++ b/WinCreds/Remove-CredentialEntry.ps1 @@ -0,0 +1,26 @@ +[CmdletBinding(SupportsShouldProcess,ConfirmImpact='High')] param ( + # Specifies a path to one or more locations. + [Parameter(Mandatory=$true, + Position=0, + ParameterSetName="ParameterSetName", + ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]]$EntryName, + [switch]$PassThru +) + +begin { +} + +process { + foreach( $local:entryname_ in $EntryName ) { + $local:Entry = $entryname_ -replace " ","" -replace "Target:","" + if ($PSCmdlet.ShouldProcess("$Entry", "Remove Credential Entry")) { + cmdkey /del:$Entry | Out-Null + if( $PassThru ) { Write-Output $Entry } + } + } +} + +end { +} \ No newline at end of file diff --git a/WinCreds/_.package.json b/WinCreds/_.package.json new file mode 100644 index 0000000000000000000000000000000000000000..e9c6e83a1c835ecdc5de856dff2d01229b9d7bbf GIT binary patch literal 1274 zcmc(eK}*9x5QX1a@IQpblQiJjn~3P4RIo@7>Y=uw)g~K>Q4sa7tKTGUF@XjHMOl)} z?##TmZ)WoO@v2?zDEeMb51MMG74L--IUQD>W>kpY^mQ7MpZ&;pn&?hm$0|6T>k;HZ zgLxBHICtdcAk4ujdCU&CyXu7$5WBwp^mZY&eU9orp}#~ywpQSDN?l6DmC6jyw9*<8 zouPS!_k~WxI-!CExrL7Kg-S#kQsI$zhGO|S zaRobzjWs0GSR-9?%RMZwXQp8cw%tDAUKix#*!xvX-;TB`)3tXE-q3ebma_UyQWsC# s=X8cb)9YIk{TJMqFk83&gL{bX1v4;P&*;I{|FZY3A>RB7sphNSUxGP)fB*mh literal 0 HcmV?d00001 diff --git a/base.win/Generate-FancyZones.ps1 b/base.win/Generate-FancyZones.ps1 new file mode 100644 index 0000000..90db4de --- /dev/null +++ b/base.win/Generate-FancyZones.ps1 @@ -0,0 +1,155 @@ +<# +Generate-FancyZones 'Sz 4K' $( +# Generate-FancyZones 'Playground' $( + [ordered]@{ + Q =@(01,01),@(01,13),@(13,01),@(13,13); + NT=@(01,01),@(10,01),@(13,01),@(16,01); + X1=@(10,01); + N1=@(16,01),@(10,01),@(01,01); + W1=@(10,01),@(13,01); + S1=@(10,01),@(22,01); + N3=@(01,11),@(16,01); + X3=@(01,11),(10,11); + XL=@(01,14),(7,14); + XX=@(01,11),(7,11); + F3=@(01,11); +}) -Verbose -WhatIf + +Generate-FancyZones 'Sz 1920x1080' $( +# Generate-FancyZones 'Playground' $( + [ordered]@{ + BNT=@(01,01); + BW1=@(11,01); + BW2=@(11,12); + BSQ=@(11,01),@(11,12),@(15,01),@(15,12) +}) -Verbose -WhatIf + +#> + +<# +#> +[CmdletBinding()]param( + + [ArgumentCompleter({ param ( + $commandName, + $parameterName, + $wordToComplete, + $commandAst, + $fakeBoundParameters + ) + $local:ptDataPath = Join-Path $env:LOCALAPPDATA "Microsoft\PowerToys" + $local:fzJsonPath = Join-Path $ptDataPath "FancyZones\zones-settings.json" + Get-Content $fzJsonPath | ConvertFrom-Json | + Select-Object -ExpandProperty 'custom-zone-sets' | + Where-Object 'type' -eq 'canvas' | + Select-Object -ExpandProperty name | + ForEach-Object { + "'$_'" + } + })] + [Parameter(Mandatory,Position=0)] + [string]$FancyZoneName, + [int]$RatioW=24,[int]$RatioH=24, + [ValidateNotNullOrEmpty()] + $presetSizes=[ordered]@{ + N1 = @(9,10) + W1 = @(12,10) + X1 = @(15,10) + F1 = @(24,10) + N2 = @(9,12) + X2 = @(15,12) + F2 = @(24,12) + N3 = @(9,14) + W3 = @(12,14) + X3 = @(15,14) + XL = @(18,11) + XX = @(18,14) + F3 = @(24,14) + NT = @(9,24) + WT = @(12,24) + XT = @(15,24) + S1 = @(3,10) + Q = @(12,12) + + BNT = @(10,24) + BW1 = @(14,11) + BW2 = @(14,13) + BSQ = @(10,13) + }, + [Parameter(ParameterSetName="AutoSections", + Mandatory,Position=1)] + $AutoSections, + [Parameter(ParameterSetName="Sections", + Mandatory,ValueFromRemainingArguments)] + [int[][]]$Sections, + [switch]$WhatIf +) + +$local:ptDataPath = Join-Path $env:LOCALAPPDATA "Microsoft\PowerToys" +$local:fzJsonPath = Join-Path $ptDataPath "FancyZones\zones-settings.json" +$fzJson = Get-Content $fzJsonPath | ConvertFrom-Json + +$local:fancyZone = $fzJson.'custom-zone-sets' | + Where-Object 'type' -eq 'canvas' | + Where-Object 'name' -eq $FancyZoneName + +if( -not $fancyZone ) { + Write-Error "`nFancy Zone $FancyZoneName not matched to a valid zone`n`n" + return +} + +$local:TotalWidth = $fancyZone.info.'ref-width' +$local:TotalHeight = $fancyZone.info.'ref-height' + +$local:wFactor = $TotalWidth / $RatioW +$local:hFactor = $TotalHeight / $RatioH + +Write-Verbose "$( + )$($fancyZone.uuid) - $($fancyZone.name)`n$(" "*10 + )W = $TotalWidth / $RatioW = $([Math]::Round($wFactor,3)); $( + )H = $TotalHeight / $RatioH = $([Math]::Round($hFactor,3));" + +$fancyZone.info.zones = @() +if( $AutoSections ) { + foreach( $local:p in $AutoSections.Keys ) { + $local:psW = [Math]::Round(($presetSizes."$p")[0] * $wFactor,0) + $local:psH = [Math]::Round(($presetSizes."$p")[1] * $hFactor,0) + $local:pairs = $AutoSections[$p] + if( $pairs[0] -is [int] ) { + $pairs = , $pairs + } + foreach( $local:s in $pairs ) { + Write-Verbose "$p : $($s | Join-String ", ")" + $fancyZone.info.zones += [ordered]@{ + X = [Math]::Round(($s[0] - 1) * $wFactor,0) + Y = [Math]::Round(($s[1] - 1) * $hFactor,0) + width = $psW + height = $psH + } + } + } +} else { + foreach ( $local:s in $Sections ) { + $fancyZone.info.zones += [ordered]@{ + X = [Math]::Round($s[0] * $wFactor,0) + Y = [Math]::Round($s[1] * $hFactor,0) + width = [Math]::Round($s[2] * $wFactor,0) + height = [Math]::Round($s[3] * $hFactor,0) + } + } +} + +$fzJson.'custom-zone-sets' | + Where-Object name -eq $FancyZoneName | + ForEach-Object { + $_.info.zones = $fancyZone.info.zones + } + +if( -not $WhatIf -and -not $WhatIfPreference ) { + if( -not (Test-Path "$fzJsonPath.bak") ) { + Copy-Item $fzJsonPath "$fzJsonPath.bak" + } + $fzJson | ConvertTo-Json -Depth 5 | Out-File $fzJsonPath +} else { + $fancyZone | ConvertTo-Json -Depth 5 +} \ No newline at end of file diff --git a/base/Find-MTU.ps1 b/base/Find-MTU.ps1 new file mode 100644 index 0000000..1f1aada --- /dev/null +++ b/base/Find-MTU.ps1 @@ -0,0 +1,69 @@ +<# + +.SYNOPSIS + Sends ICMPv4 echo request packets to a given IPv4 address + with various payload sizes until the maximum transmission unit is found. + +.DESCRIPTION + Inspired by the script of Charles_1.0 I created a function that uses + the .Net ping class to find the biggest transmission unit size. + It simple and fast. + Just open Powershell, run the script and type Find-MTU to get the result. + +.INPUTS + None + You cannot pipe input to this cmdlet. + +.OUTPUTS + The function returns an integer that represents the MTU size. + +.NOTES + Author: G.A.F.F. Jakobs + Version: 1.3 + +.EXAMPLE + Find-MTU 192.168.1.254 + +.LINK + http://gallery.technet.microsoft.com/Find-the-Biggest-MTU-size-ff1c6069 + +#> + +[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')] +Param( + [parameter(Mandatory = $true, Position = 0)] + [System.Net.IPAddress]$IPaddress +) + +$Ping = New-Object System.Net.NetworkInformation.Ping +$PingOptions = New-Object System.Net.NetworkInformation.PingOptions +$PingOptions.DontFragment = $true + +[int]$Timeout = 1000 +[int]$SmallMTU=1 +[int]$LargeMTU=35840 + +[byte[]]$databuffer = ,0xAC * $LargeMTU + + +#action + +While (-not ($SmallMTU -eq ($LargeMTU - 1))) { + [int]$xTest= ($LargeMTU - $SmallMTU) / 2 + $SmallMTU + + $PingReply = $Ping.Send($IPaddress, $Timeout, $($DataBuffer[1..$xTest]), $PingOptions) + Write-Verbose "testing $($xTest + 28) byte transmission unit size" + if ($PingReply.Status -match "Success"){ + $SmallMTU = $xTest + } + else{ + $LargeMTU = $xTest + } + Start-Sleep -Milliseconds 50 +} + +If($SmallMTU -eq 1){ + Write-Error "The IP address $IPaddress does not respond." +}else{ + return $SmallMTU + 28 # add 28 bytes because 20 bytes are reserved for the IP header and 8 bytes must be allocated for the ICMP Echo Request header. +} \ No newline at end of file diff --git a/base/Get-FreeDiskSpace.ps1 b/base/Get-FreeDiskSpace.ps1 new file mode 100644 index 0000000..8c67261 --- /dev/null +++ b/base/Get-FreeDiskSpace.ps1 @@ -0,0 +1 @@ +Get-CimInstance -ClassName Win32_LogicalDisk | Select-Object -Property DeviceID,@{'Name' = 'FreeSpace (GB)'; Expression= { [int]($_.FreeSpace / 1GB) }} \ No newline at end of file diff --git a/xserver/Invoke-XApp.ps1 b/xserver/Invoke-XApp.ps1 new file mode 100644 index 0000000..a98a0a1 --- /dev/null +++ b/xserver/Invoke-XApp.ps1 @@ -0,0 +1,107 @@ +<# +.SYNOPSIS + Invoke a graphical application on X-Server. +.DESCRIPTION + Invoke a graphical application, making sure an X server connection is active, start the x-server if needed, and if the application is remote, make sure the remote session has the correct DISPLAY values set. +.INPUTS + Inputs to this cmdlet (if any) +.OUTPUTS + Output from this cmdlet (if any) +.NOTES + General notes +.EXAMPLE + Invoke-XApp xclock +.EXAMPLE + Invoke-XApp xclock -Remote remote@example.com +.COMPONENT + The component this cmdlet belongs to +.ROLE + The role this cmdlet belongs to +.FUNCTIONALITY + The functionality that best describes this cmdlet +#> +[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] +#[OutputType([String])] + +# # Param2 help description +# [Parameter(ParameterSetName='Parameter Set 1')] +# [AllowNull()] +# [AllowEmptyCollection()] +# [AllowEmptyString()] +# [ValidateScript({$true})] +# [ValidateRange(0,5)] +# [int] +# $Param2, + +# # Param3 help description +# [Parameter(ParameterSetName='Another Parameter Set')] +# [ValidatePattern("[a-z]*")] +# [ValidateLength(0,15)] +# [String] +# $Param3 +Param ( + # Param1 help description + [Parameter(Mandatory, Position = 0, ParameterSetName = 'Parameter Set 1')] + [string[]]$Command, + [string[]]$Remote, + [ValidateSet('pwsh', 'bash', 'zsh', 'sh')] + [string]$RemoteShell = 'pwsh', + [string]$PrivateKeyPath +) + +begin { + $null = Get-Command 'xlaunch' -ErrorAction Stop + + if ( -not $(Get-Process -ProcessName 'vcxsrv' -ErrorAction SilentlyContinue) ) { + + $local:LaunchCfg = $env:XLAUNCH_CONFIG + if ( -not $env:XLAUNCH_CONFIG ) { + New-TemporaryFile | Tee-Object -Variable 'LaunchCfg' | Remove-Item + } + Write-Verbose "LaunchCfg=$LaunchCfg" + if ( -not (Test-Path $LaunchCfg) ) { + Write-Verbose "Creating missing $LaunchCfg..." + New-Item -ItemType File -Path $LaunchCfg -Value @( + '' + , '' ) + } + + & xlaunch --run $LaunchCfg + } +} + +process { + if ( -not "Command" ) { + Write-Warning "No command supplied, exiting." + return + } + if ($pscmdlet.ShouldProcess("Target", "Operation")) { + if ( $Remote ) { + $local:RemoteCommand = "bash", "-c", "'DISPLAY=`"localhost:`"`$( xauth list | awk `"{ print `$1 }`" | cut -d: -f2 | tail -1 ) $Command'" + & ssh -i $PrivateKeyPath $Remote $RemoteCommand + } + } +} + +end { +} \ No newline at end of file diff --git a/xserver/_.package.json b/xserver/_.package.json new file mode 100644 index 0000000000000000000000000000000000000000..5adf068e6f9c9889ff665ed54954e25db5c997af GIT binary patch literal 1116 zcmc&y!3u&v6r6L=Kgc^5bne=r4$&n#MF%mlNG(jGh6SD*wSfr*4n4>=bh_>U@$Pogr>MLdy8E F_y&KyV#ELd literal 0 HcmV?d00001