Skip to content

Instantly share code, notes, and snippets.

@mhudasch
mhudasch / Uninstall-ProjectNuGetPackage.ps1
Last active February 14, 2019 09:23
Uninstalles all nuget packages from all projects in a solution
@( Get-Project -All | ? { $_.ProjectName } | % { Get-Package -ProjectName $_.ProjectName } ) | %{ $_ | Add-Member -MemberType "NoteProperty" -Value "$($_.Id)@$($_.Version)" -Name "Key"; $_ } | Sort -Property "Key" -Unique | %{ Uninstall-Package -Id $_.Id -ProjectName $_.ProjectName -Force -RemoveDependencies -ErrorAction Ignore }
@mhudasch
mhudasch / Get-NugetLicense.ps1
Last active August 5, 2021 14:50
Extract all license infomation of all used nuget packages
$lic = New-Item -ItemType Directory -Name "lic" -Force -ErrorAction "Stop";
$projects = @( Get-Project -All | ? { $_.ProjectName } | % { Get-Package -ProjectName $_.ProjectName } );
$deps = $projects | %{ $_ | Add-Member -MemberType "NoteProperty" -Value "$($_.Id)@$($_.Version)" -Name "Key"; $_ } | Sort -Property "Key" -Unique;
$deps | %{ $pkg = $_; if($null -eq $pkg.LicenseUrl) { Set-Content -Path ($lic.FullName + "\no_license_" + $pkg.Id + ".txt") -Value "NO-LICENCE" } }
$loaded = $deps | %{ $pkg = $_; if($null -ne $pkg.LicenseUrl) { Try { $extMatch = [regex]::Match($pkg.LicenseUrl, '^.*?(\.html?|\.txt)$'); if($extMatch.Success){$ext = $extMatch.Groups[1].Value;} else {$ext = ".html"} $cnt = (New-Object System.Net.WebClient).DownloadString($pkg.LicenseUrl); Write-Host "$($pkg.LicenseUrl) downloaded for $($pkg.Id)."; @{ PKg = $pkg; Content = $cnt; } | Write-Output } Catch [system.exception] { Write-Host "Could not download license for $($pkg.Id) -> '$($pkg.LicenseUrl)'" } } }
$loaded | %{ $pkg = $_["Pkg"];
@mhudasch
mhudasch / Get-WindowsCredentialManagerPSCredential.ps1
Created January 23, 2018 06:50
Get Credentials from Windows Credentials Manager
#requires -version 5
Set-StrictMode -Version Latest
function Get-WindowsCredentialManagerPSCredential {
[CmdletBinding()]
param(
[Parameter(Position = 0, Mandatory = $true)]
[Alias("Name")]
[ValidateNotNullOrEmpty()]
[string]$Url
@mhudasch
mhudasch / InjectedView.cs
Created July 27, 2017 07:45
Inject a View into another
[DefaultProperty("ViewPropertyBindings")]
[ContentProperty("ViewPropertyBindings")]
internal class InjectedView : FrameworkElement
{
private readonly IKernel kernel;
private FrameworkElement visual;
private ObservableCollection<ViewPropertyBinding> viewPropertyBindings;
@mhudasch
mhudasch / pre-commit-encoding.ps1
Created November 9, 2016 16:45
Git local pre-commit hook script that ensures correct file encoding
function Get-FileEncoding {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] [string]$Path
)
[byte[]]$byte = get-content -Encoding byte -ReadCount 4 -TotalCount 4 -Path $Path
$encoding = 'utf8';
if ( $byte[0] -eq 0xef -and $byte[1] -eq 0xbb -and $byte[2] -eq 0xbf )
{ $encoding = 'utf8-with-bom'; }
elseif (($byte[0] -eq 0xfe -and $byte[1] -eq 0xff) <#big endian#>)
@mhudasch
mhudasch / Add-StartupCommand.ps1
Created October 13, 2016 15:57
Schedule an auto-start command to a remote machine with given rights and integrated cleaup after it ran leaving possible piped results.
#requires -version 5
Set-StrictMode -Version Latest
Function Add-StartupCommand {
[OutputType("ScheduledCommand")]
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0)]
[String]$TaskName,
[Parameter(Mandatory=$true,Position=1)]
@mhudasch
mhudasch / Invoke-ScheduledCommand.ps1
Last active February 9, 2017 20:44
Invoke a command via the task scheduler on any computer
#requires -version 5
Set-StrictMode -Version Latest
Function Invoke-ScheduledCommand {
[Diagnostics.CodeAnalysis.SuppressMessage("PSUseDeclaredVarsMoreThanAssignments", "", Justification = "This re-establishes the global environment preferences. They can be used all over child scripts.")]
[OutputType("ScheduledCommandResult[]")]
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0)]
[String]$TaskName,
@mhudasch
mhudasch / Add-EnvironmentPath.ps1
Last active September 27, 2016 14:41
Add a path to the machine PATH environment variable
Function Add-EnvironmentPath {
<#
.SYNOPSIS
Adds a path to the PATH environment variable at give scope.
.DESCRIPTION
Adds a Path to the PATH environment variable stored in the current process or in the Windows operating system registry key reserved for the current user or local machine.
In addition to that the command sorts the paths and removes duplicates.
.PARAMETER Path
@mhudasch
mhudasch / Read-Choice.ps1
Last active October 27, 2016 16:01
Test of Input mask for PS
#requires -version 5
Set-StrictMode -Version Latest
Function Read-Input {
[Diagnostics.CodeAnalysis.SuppressMessage("PSAvoidUsingWriteHost", "", Justification = "This is an interface cmdlet that should be seen in its host.")]
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, Position=1)]
[string]$Message,
[Parameter(Mandatory=$false, Position=2)]
@mhudasch
mhudasch / Write-Robot.ps1
Created September 20, 2016 22:19
Draw a waiting wall-e
Function Robot {
$overallIndex = 0;
$cx = $Host.UI.RawUI.CursorPosition.X;
$cy = $Host.UI.RawUI.CursorPosition.Y;
$left = 0;
$right = $Host.UI.RawUI.BufferSize.Width;
$sIdx = 0;
$uIdx = 0;
$stg = "walk";