Skip to content

Instantly share code, notes, and snippets.

View camilohe's full-sized avatar

Camilo E. Hidalgo Estevez camilohe

View GitHub Profile
@camilohe
camilohe / Add-TypeDefinition.ps1
Created November 12, 2019 16:18 — forked from altrive/Add-TypeDefinition.ps1
Add-Type wrapper cmdlet. UseTypeAlias=$true to avoid type name conflict.when Add-Type called multiple times. See also https://gist.github.com/altrive/6765957
function Add-TypeDefinition
{
[CmdletBinding()]
param (
[string] $Path,
[string[]] $ReferencedAssemblies = @("Microsoft.CSharp"),
[string] $OutputAssembly,
[switch] $IgnoreWarnings,
[switch] $UseTypeAlias
)
@camilohe
camilohe / PSNuGet.ps1
Created November 12, 2019 16:17 — forked from altrive/PSNuGet.ps1
Sample code to use NuGet as PowerShell package manager
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$Script:PackageManager = $null
function Initialize-NuGetPackageManager
{
[CmdletBinding()]
param (
[hashtable] $Repositories = @{},
@camilohe
camilohe / ParallelPing.ps1
Created November 12, 2019 16:17 — forked from altrive/ParallelPing.ps1
Sample code to execute ping in parallel
function Main
{
$ipAddresses = 1..254 | foreach { "192.168.0.$_" }
#$ipAddresses | Invoke-ParallelPing | Out-GridView
Invoke-ParallelPing -ComputerName $ipAddresses | Out-GridView
}
function Invoke-ParallelPing
{
@camilohe
camilohe / SetAccountPrevilage.ps1
Created November 12, 2019 16:16 — forked from altrive/SetAccountPrevilage.ps1
Sample code to set LSA account previlage via P/Invoke(LsaAddAccountRights).
#Requires -RunAsAdministrator
function Main
{
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"
#Target account to assign previlage
$svcAccount = "TestSvc"
@camilohe
camilohe / Add-InternetExploreZoneSetting.ps1
Created November 12, 2019 16:15 — forked from altrive/Add-InternetExploreZoneSetting.ps1
Configure Internet Explorer security zone settings.
<#
.SYNOPSIS
Configure Internet Explorer SecurityZone Settings.
.DESCRIPTION
Note: Configration is not applied immediately, Need to restart related services to apply zone settings.
.LINK
http://support.microsoft.com/kb/184456/en-us
@camilohe
camilohe / RemoteFileTransferTest.ps1
Created November 12, 2019 16:12 — forked from altrive/RemoteFileTransferTest.ps1
PowerShell v5 Remote File Transfer feature usage
#Requires -RunAsAdministrator
#Requires -Version 5.0
$ErrorActionPreference = "Stop"
function Main
{
#Size of dummy file, that transffered by PSRemoting.
$fileSize = 10MB
@camilohe
camilohe / ToastNotification_Windows10.ps1
Created November 12, 2019 16:12 — forked from altrive/ToastNotification_Windows10.ps1
Windows 10 toast notification sample
$ErrorActionPreference = "Stop"
$notificationTitle = "Notification: " + [DateTime]::Now.ToShortTimeString()
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)
#Convert to .NET type for XML manipuration
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null
@camilohe
camilohe / PowerShellv5_UsingNamespace.ps1
Created November 12, 2019 16:11 — forked from altrive/PowerShellv5_UsingNamespace.ps1
PowerShell v5 'using namespace' syntax test
#Require -Version 5.0
# using statement must appear before any other statements in a script.
# other using types(Assembly/Command/Module/Type) is not supported yet?
# [Enum]::GetNames('System.Management.Automation.Language.UsingStatementKind')
using namespace System.Diagnostics
using namespace System.Linq
function Main
{
@camilohe
camilohe / Test-Remotely.ps1
Created November 12, 2019 16:11 — forked from altrive/Test-Remotely.ps1
Remotely PowerShell Module Tests
function Test-Message
{
Write-Verbose "Test Message" -Verbose
}
Describe "Test-Remotely"{
It "Send local function to remote session"{
#Arrange: Send local function definition to remote session
Remotely ([ScriptBlock]::Create(${Function:Test-Message}.Ast.Extent.Text))
<Query Kind="Program">
<NuGetReference>Newtonsoft.Json</NuGetReference>
<NuGetReference Version="4.5.0-alpha01" Prerelease="true">NLog</NuGetReference>
<Namespace>NLog</Namespace>
<Namespace>NLog.Config</Namespace>
<Namespace>NLog.Targets</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
</Query>
void Main()