This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #requires -Version 5 | |
| Get-Package | foreach{ | |
| $attributes = $_.meta.attributes | |
| $htProps = [Ordered]@{msiGUID=''} | |
| for ($i=0;$i -lt $attributes.keys.count;$i++){ | |
| $htProps.Add($attributes.keys[$i].LocalName,$attributes.values[$i]) | |
| } | |
| if ($htProps.Contains('DisplayName')){ | |
| $uninstallString = $htProps.UninstallString | |
| $modifyPath = $htProps.ModifyPath |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Restart-Process{ | |
| [CmdletBinding()] | |
| param([Parameter(ValueFromPipeline = $true)] $process) | |
| Begin{ | |
| $selectedIndex=$multiInstanceName=$null | |
| } | |
| Process{ | |
| if ($multiInstanceName -eq $_.Name){continue} | |
| $procToRestart=$_ | |
| #handle if there are multiple instances of the same application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #https://datamarket.azure.com/account/keys | |
| #Home -> My Account -> Account Keys: | |
| #based on http://www.powershelladmin.com/wiki/Accessing_the_Bing_Search_API_v2_using_PowerShell | |
| function Get-BingSearchResult($query){ | |
| Add-Type -Assembly System.Web | |
| $Key = 'YOURACCOUNTKEY' | |
| $Base64KeyBytes = [byte[]] [Text.Encoding]::ASCII.GetBytes("ignored:$Key") | |
| $Base64Key = [Convert]::ToBase64String($Base64KeyBytes) | |
| $QueryString = '%27' + [Web.HttpUtility]::UrlEncode($query) + '%27' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-RandomUser { | |
| <# | |
| .SYNOPSIS | |
| Generate random user data. | |
| .DESCRIPTION | |
| This function uses the free API for generating random user data from https://randomuser.me/ | |
| .EXAMPLE | |
| Get-RandomUser 10 | |
| .EXAMPLE | |
| Get-RandomUser -Amount 25 -Nationality us,gb -Format csv -ExludeFields picture |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ConvertFrom-ExcelClipboard { | |
| <# | |
| .SYNOPSIS | |
| Convert copied range from excel to an array of PSObjects | |
| .DESCRIPTION | |
| A range of cells copied into the clipboard is converted into PSObject taking the first row (or provided property names via Header parameter) as the properties. | |
| .EXAMPLE | |
| #Considering a range of cells including header has been copied to the clipboard | |
| ConvertFrom-ExcelClipboard | |
| .EXAMPLE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $htUsers = @{} | |
| $htProps = @{} | |
| $addADGroupMembers.Keys | foreach {$htProps.$_=$null} | |
| foreach ($group in $addADGroupMembers.GetEnumerator()){ | |
| foreach ($user in $group.Value){ | |
| if (!$htUsers.ContainsKey($user)){ | |
| $htProps.UserID = $user | |
| $htUsers.$user = $htProps.Clone() | |
| } | |
| ($htUsers.$user).$($group.Name) = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function New-PowershellWebGUI ($HTMLRaw,$Title,$Runspace) { | |
| [xml]$xaml = @" | |
| <Window | |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
| Title="$Title" Height="500" Width="700"> | |
| <Grid> | |
| <DockPanel> | |
| <WebBrowser Name="WebBrowser" DockPanel.Dock="Top" Margin="30"> | |
| </WebBrowser> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function Show-Diff { | |
| param([String[]]$OldString,[String[]]$NewString) | |
| $WebPage = @" | |
| <!DOCTYPE HTML> | |
| <html> | |
| <head> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Show-HTML ([string]$HTML){ | |
| Add-Type –AssemblyName PresentationFramework | |
| if(Test-Path $HTML -IsValid){ | |
| $txt = Get-Content $HTML -Raw | |
| $HTML = $txt | |
| } | |
| $HTML.Replace('<head>','<meta name="viewport" content="width=device-width, initial-scale=1"><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta http-equiv="Content-Type" content="text/html;charset=utf-8">') | |
| [xml]$XAML = @' | |
| <Window | |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function New-PSWebServer { | |
| <# | |
| .Synopsis | |
| Creates a web server that will invoke PowerShell code based on routes being asked for by the client. | |
| .Description | |
| New-PSWebServer creates a web server. The web server is composed of a schema that defines the client's requests to routes where PowerShell code is executed. | |
| Under the covers, New-PSWebServer uses the HTTPListener .NET class to execute powershell code as requested, retrieves the results and sends data back through the httplistener web server framework. |