Last active
January 22, 2021 13:03
-
-
Save esperecyan/4ba2f3dbc8de58bc2df7e5715e1e7f2a to your computer and use it in GitHub Desktop.
ダブルクリックで実行できるPowerShellスクリプトファイルのテンプレート。UTF-8 (BOMなし) で保存してください。MIT License https://opensource.org/licenses/mit-license
This file contains 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
#@~^AQAAAA==~IAAAAA==^#~@ function toPSString(str) { return "'" + str.replace(/%/g, '"%"').replace(/'/g, "''") + "'"; } /* -*- mode: powershell;-*- | |
<#*/ var command = 'param($Test)' | |
+ '; $_PSCommandPath = ' + toPSString(WSH.ScriptFullName) | |
+ '; Invoke-Expression (Get-Content ' + toPSString(WSH.ScriptFullName) + ' -Encoding UTF8 -Raw)'; | |
var namePattern = /^-(?!(?:b(?:and|or|xor|not)|sh[lr]|[ic]?(?:eq|ne|gt|ge|lt|le|(?:not)?(?:like|match|contains|in)|replace|split)|join|is(?:not)?|as|and|or|not|f)$)[0-9a-z]+$/i; | |
var args = ''; for (var i = 0; i < WSH.Arguments.Length; i++) { | |
var arg = WSH.Arguments(i); args += ' ' + (namePattern.test(arg) ? arg : toPSString(arg)); } | |
WSH.CreateObject('WScript.Shell').Run('PowerShell -NoExit -Command &{' + command + '}' + args); /*#> | |
#Requires -Version 5.0 | |
using namespace System.Windows.Forms | |
Set-StrictMode -Version Latest; $ErrorActionPreference = 'Stop'; | |
$PSCommandPath = $_PSCommandPath; $PSScriptRoot = Split-Path $PSCommandPath -Parent | |
Add-Type -AssemblyName @('System.Windows.Forms') | |
[MessageBox]::Show( | |
"-Testパラメータの値: $Test`n`$PSCommandPath: $PSCommandPath`n`$PSScriptRoot: $PSScriptRoot", | |
'PowerShellテスト🐚' | |
) | |
(Get-Process -Id $pid).CloseMainWindow() | Out-Null # */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment