Skip to content

Instantly share code, notes, and snippets.

@altrive
altrive / CreateNanoServerVHD.ps1
Last active October 11, 2016 16:10
Create Nano Server VHDX file from WIM
#Requires -RunAsAdministrator
#Requires -Version 3.0
#References:
#Getting Started with Nano Server <https://technet.microsoft.com/en-us/library/mt126167.aspx>
#Quick Guide - Deploying Nano Server using PowerShell <http://deploymentresearch.com/Research/Post/479/Quick-Guide-Deploying-Nano-Server-using-PowerShell>
param (
#[ValidateScript({ Test-Path $_ })]
$ConvertWindowsImageScriptPath = 'D:\work\NanoServerSetup\Convert-WindowsImage.ps1'
@altrive
altrive / PSv5_Preview_Features.md
Last active April 24, 2016 16:45
PowerShell v5 Undocumented Features List
Note: Following features are tested on Windows 10 Preview Build 10074 environment

PSReadLine

Windows 10 Preview contains PSReadLine module at "%ProgramFiles%\WindowsPowerShell\Modules" (WMF 5.0 Preview don't contain this modules)

PSReadLine is automatically loaded when PSConsoleHost launched(if available). This feature can be controlled by following command.

@altrive
altrive / PowerShellv5_UsingNamespace.ps1
Last active November 12, 2019 16:11
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
{
@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 / RemoteFileTransferTest.ps1
Last active November 12, 2019 16:12
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
@altrive
altrive / EventTracingManagement.ps1
Created May 1, 2015 22:23
EventTracingManagement Cmdlets Test (added in Windows 10)
$ErrorActionPreference = "Stop"
Import-Module EventTracingManagement #Require Windows 10 enviroment(it use underlying CIM APIs https://msdn.microsoft.com/en-us/library/dn919685%28v=vs.85%29.aspx)
Use-NuGetPackage Microsoft.Diagnostics.Tracing.TraceEvent -Verbose #Require PSNuGet<https://github.com/altrive/PSNuGet>
$sessionName = "MyRealTimeSession"
$providerName = "Sample.EtwTrace"
$providerGuid = [Microsoft.Diagnostics.Tracing.Session.TraceEventProviders]::GetEventSourceGuidFromName($providerName)
try
{
@altrive
altrive / RazorEngineTest.ps1
Last active August 29, 2015 14:19
RazorEngine Test
#Require PSNuGet<https://github.com/altrive/PSNuGet>
Use-NuGetPackage RazorEngine -Version 3.6.6 -Verbose
# テンプレート
$template = @'
Hello @Model.Name! Welcome to Razor!
@if (Model.ShowDetail) {
@:Plain Text!! はろー
}
@altrive
altrive / Show-PropertyGridVew.ps1
Created April 4, 2015 10:59
Sample code to use Exxtended WPF Toolkit PropertyGrid
#Require -Version 5.0
$ErrorActionPreference = "Stop"
Use-NuGetPackage -PackageId Extended.Wpf.Toolkit -Verbose #Require PSNuGet package <https://github.com/altrive/PSNuGet>
function Main
{
class AAA
{
[int] $AAA
@altrive
altrive / Example.ps1
Last active August 29, 2015 14:15
Enable [OutputType] validation
Set-OutputTypeValidationMode
function Main
{
Test-ShouldReturnInt32
Test-ShouldReturnVoid
}
#region function definitions
function Test-ShouldReturnInt32
@altrive
altrive / Cevio.ps1
Last active March 23, 2020 02:50
Call CeVIO .NET API by PowerShell
if([Environment]::Is64BitProcess){
throw "64bitプロセス内だとDLLロードに失敗する"
}
$ErrorActionPreference = "Stop"
Add-Type -Path "${env:ProgramFiles(x86)}\CeVIO\CeVIO Creative Studio\CeVIO.Talk.RemoteService.dll"
[CeVIO.Talk.RemoteService.ServiceControl]::StartHost($true) >$null
$talker = New-Object CeVIO.Talk.RemoteService.InteroperableComponents.Talker