Skip to content

Instantly share code, notes, and snippets.

@altrive
altrive / Install-VisualStudio.ps1
Last active March 29, 2024 14:27
Unattend install script for Visual Studio 2012 and Visual Studio 2012 Update 2
function Install-VisualStudio
{
[CmdletBinding()]
param (
[string] $ImagePath,
[string[]] $ArgumentList,
[string] $InstallPath,
[string] $ProductKey
)
Write-Verbose "Install Visual Studio 2012..."
@altrive
altrive / config.ps1
Created November 23, 2013 17:02
Sample config to create Hyper-V VM
#global variable
$global:ctx = @{
VmName = "Windows 8.1"
Operation = ""
Session = $null
ComputerName = "TestPC"
DomainJoin =@{
Name = "TEST.local"
Credential = Get-SavedCredential -Id DomainAdmin
@altrive
altrive / Install-SysInternalsTool.ps1
Last active March 18, 2024 12:26
Install and setup script for SysInternals tools(BGInfo/AutoLogon).
#Install SysInternals BGInfo/AutoLogon tools
function Install-SysInternalsTool
{
#Target directory is %WinDir%C:\Windows\System32\SysInternals
$targetDir = Join-Path $env:WinDir "System32\SysInternals"
#Tools to be downloaded
$tools = @{
Bginfo = "http://live.sysinternals.com/Bginfo.exe"
Autologon = "http://live.sysinternals.com/Autologon.exe"
@altrive
altrive / ToastNotification_Windows10.ps1
Last active November 17, 2023 14:21
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
@altrive
altrive / Test-RebootRequired.ps1
Last active August 3, 2023 14:34
Check pending reboot on local computer
#Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542>
function Test-RebootRequired
{
$result = @{
CBSRebootPending =$false
WindowsUpdateRebootRequired = $false
FileRenamePending = $false
SCCMRebootPending = $false
}
@altrive
altrive / PowerShellv4_DynamicKeyword.md
Last active August 3, 2023 02:28
Test code of PowerShell v4 Dynamic Keyword

Define DynamicKeyword

Define DynamicKeyword 'ExecTest'

Note: Don't copy&paste from following code. PowerShell SyntaxHighlighter remove some lines. Instead, use RAW view.

#Requires -Version 4.0
Set-StrictMode -Version Latest
@altrive
altrive / Add-WindowsDefenderExclusionsPolicy.ps1
Last active June 21, 2023 18:14
Add WindowsDefender exclusions policies for Windows 8 Hyper-V
function Add-WindowsDefenderExclusionsPolicy
{
$ErrorActionPreference="Stop"
Set-StrictMode -Version Latest
#Get Hyper-V Settings
$vmHost = Get-VMHost
#Default Exclusion Entries
$excludes = @{
@altrive
altrive / Add-ISEAddinWithMultiKeyShortcut
Last active May 23, 2023 13:51
PowerShell ISE don't support multi-sequence keyboard shortcuts like Ctrl+K,Ctrl+D by default. It need to create MultiKeyGesture class inherited from KeyGesture.
$ErrorActionPreference = "Stop"
function Main
{
if ($Host.Name -ne "Windows PowerShell ISE Host"){
return
}
$menus = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus
@altrive
altrive / Out-HtmlView.ps1
Created August 14, 2013 01:39
Cmdlet to show object tree in HtmlView
#TODO:support for non serializable object(example:PSCustomObject)
function Out-HtmlView
{
[CmdletBinding()]
param(
[Parameter()]
[int]$Depth = 2,
[Parameter(Mandatory,ValueFromPipeLine)]
$InputObject
)
@altrive
altrive / Add-InternetExploreZoneSetting.ps1
Created March 3, 2014 06:35
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