Windows OS ã«ããã¦ãããã¯ã¢ããã¹ã¯ãªãããæ¸ããã¨ããã®ã§ãããcmd.exe ã®ããããã¡ã¤ã«ã.batãã¡ã¤ã«ãã§æ¸ãã®ã¯è¾ãã®ã§ Powershell ã®ã¹ã¯ãªããã.ps1ãã¡ã¤ã«ãã¨ãã¦æ¸ããã¨ã«ãã¾ããã
Powershell ã¯ãã·ã§ã«ï¼OSã®ã³ãã³ãã©ã¤ã³UIï¼ã¨ãã¦ã¯ä½¿ã£ã¦ã¾ãããããã°ã©ãã³ã°è¨èªã¨ãã¦ã® Powershell ã¯ãã¾ãç¥ãã¾ããã§ãã*1ã
ã¡ãã£ã¨ã ãï¼ããã¯ã¢ããã¹ã¯ãªãããæ¸ãããã«å¿ è¦ãªã ãï¼ããã°ã©ãã³ã°è¨èª Powershell ã調ã¹ã¦ã¿ã¾ããã
å 容ï¼
- å ¨è¬çãªå°è±¡
- ã³ãã³ããã³ãã³ãã¬ãããé¢æ°ãæ¼ç®å
- é¢æ°ã®å ¥åºå
- Powershell ã®ã³ã¼ããã¤ã©ã¤ã
- ãã¼ãã³ã°ã³ã³ãã³ã·ã§ã³ã¨åè©
- åã®æå®
- ã¨ã©ã¼å¦ç
- ä½è«ï¼ ããããã¡ã¤ã«ã«ã¦ã³ã¶ãªãã話
- ãã®ä»ã®è¨èªæ©è½
- ãããã«
å ¨è¬çãªå°è±¡
ããã°ã©ãã³ã°è¨èªã¨ãã¦ã® Powershell ã¯ãã·ã§ã«ã¹ã¯ãªããè¨èªã®ä¼çµ±ã«æ²¿ã£ã¦ãã¾ãããã¤ãã©ã¤ã³ã®ãããªã·ã§ã«ç¬èªã®æ©è½ãæã¤ã®ã§ãé常ã®ããã°ã©ãã³ã°è¨èªã¨ã¯ã¡ãã£ã¨éã£ãï¼å¥å¦ã¨ãè¨ããï¼è¨èªä»æ§ãæã¡ã¾ããå¾ã§è¿°ã¹ãé¢æ°ã®å ¥åºåã¯ãã®æãããã®ã§ãããã
Powershell ã¯ã.NET Framework ã«è¼ã£ã¦ããè¨èªå¦çç³»ã§ãã.NET ãæã¤è±å¯ãªãã¼ã¿åããã®ããããã£ï¼ã¡ã½ãããå©ç¨ã§ãã¾ãããã®é¨åã¯ãbash ã®ãããªå¾æ¥ã®ã·ã§ã«ã¹ã¯ãªããè¨èªã¨ã¯å¤§ããéãé¨åã§ããä¾ãã°ã[Math]::cos([Math]::PI)
ï¼ä¸è§é¢æ°ã®å¼ã³åºãï¼ãªãã¦è¨ç®ãã§ãã¾ãã.NET ã®æ©è½ã«ã¢ã¯ã»ã¹ããé¨åã¯ï¼ããããå¿
ç¶çã«ï¼ C# ã£ã½ãå°è±¡ãããã¾ãã
Perl ã Ruby ã®ãããªè»½éè¨èªã®å½±é¿ãåãã¦ããããã§ããSchema ã®é¦ããæãããã¨ãããã¾ããPowershell ã¯2000年代ã«çã¾ããè¨èªãªã®ã§ã20ä¸ç´ã®è¨èªéãè²ã ã¨åèã«ãã¦ããããã§ãã
ãããªäºæ ã§ãPowershell ã®è¨èªä»æ§ã¯ä¸è²«æ§ããªãå¯ãéãã®å°è±¡ãããã¾ããä¸è²«æ§ããªãè¨èªã¯ãæ§æãæåãäºæ¸¬ãã«ããã¦ãæ¶ãããã¨ãå¤ãã®ããã¡ãªããã§ãããã£ã¨ããä¸è²«æ§ããªãã®ã¯ã·ã§ã«ã¹ã¯ãªããè¨èªã®ä¼çµ±ã ã¨ãè¨ãã¾ãï¼ãããã ããã·ã§ã«ã¯â¦ãåç §ï¼ã
ã¯ã»ã®å¼·ãã楽ããã ããæ§ã ãªè¨èªããåãç¶ãã ç¹æ§ã®ãã¬ã³ãå ·åãæã§ãã¨ããä»ãåãæ¹ãããããç¥ãã¾ããã
ã³ãã³ããã³ãã³ãã¬ãããé¢æ°ãæ¼ç®å
Powershell ç¬èªã®è¨èã«ãã³ãã³ãã¬ãããcommandletãããããã¾ã*2ãæ®éã®ï¼å¾æ¥ããããç¥ãããï¼è¨èã§è¨ãã°ãå é¨ã³ãã³ããã§ããã·ã§ã«èªä½ã«å èµããã¦ããã³ãã³ãã§ããã
åã«ã³ãã³ãã¨ããã°ãå¤é¨ã«ããå®è¡å¯è½ãã¡ã¤ã«ã®ãã¨ã®ããã§ãããç´ããããã®ã§ãå®è¡å¯è½ãã¡ã¤ã«ã¯å¤é¨ã³ãã³ãã¨ãããã¨ã«ãã¾ãã
é¢æ°ã¯ãPowershell è¨èªã§æ¸ãããå®è¡åä½ã®ãã¨ã§ããï¼ã³ãã³ãã¬ããã¯ä¸»ã« C# ã§å®è£ ããã¦ããããã§ããï¼ã¦ã¼ã¶ã¼ã追å ããâã³ãã³ãâã¯é¢æ°ã§ããPowershellããã°ã©ãã³ã°ã®ä¸»ããä½æ¥ã¯ãé¢æ°ãå®ç¾©ãããã¨ã§ããé¢æ°ã®ç¹å¥ãªãã®ã¨ãã¦ãã£ã«ã¿ã¼ãããã¾ãããããã¯é¢æ°ã¨ãã¦åãæ±ã£ã¦ããã§ãããã
'+'ï¼è¶³ãç®ï¼ã '*'ï¼æãç®ï¼ã®ãããªæ¼ç®åã¯æ®éã«ããã¾ãããPowershell ã§ã¯ãã¤ãã³ããå§ã¾ãååã®æ¼ç®åãããã¾ããä¾ãã°ãè«çæ¼ç®åã§ãã AND, OR 㯠-and, -or ã§ããæ¯è¼æ¼ç®åã ==, <, <= ã§ã¯ãªã㦠-eq, -lt, -le ã§ã*3ããã©ã¼ãããæ¼ç®å -f ã¨ããæååã®é£çµï¼åå²ãè¡ãæ¼ç®å -join, -split ã¨ããããã¾ãããã¤ãã³å§ã¾ãã®æ¼ç®åã¨ããã¨ãUnix系㮠test ã³ãã³ããæãåºãã¾ããï¼ãtestã³ãã³ãã®ãã¤ãã³ãã³ãã£ã©ãæ¶ããããªããåç §ï¼ã
çµå±ãPowershell ã«ããã¦âå®è¡ã§ãããã®âã¯ä»¥ä¸ã®4種é¡ã ã¨æã£ã¦ããã§ãããã
- å¤é¨ã³ãã³ã
- ã³ãã³ãã¬ãã
- é¢æ°ï¼ãã£ã«ã¿ã¼ãå«ãï¼
- æ¼ç®å
å¤é¨ã³ãã³ããã³ãã³ãã¬ãããé¢æ°ã¯ãããç¨åº¦ã¯åãããã«æ±ããããã«ãªã£ã¦ãã¾ããããã¾ã§ãããç¨åº¦ã¯ãã§ããã
Powershellè¨èªã®é¢æ°ã« CmdletBinding ã¨ããå±æ§ãä»ãã¦ããä½æ³ã«å¾ã£ãæ¸ãæ¹ãããã¨ããã¤ãã£ããªã³ãã³ãã¬ããï¼ã³ã³ãã¤ã«è¨èªã§å®è£ ããã¦ã.NETãã¤ããªã«ã³ã³ãã¤ã«ãããã³ã¼ãï¼ã¨åºå¥ã§ããªãé¢æ°ãä½ããããã§ããã詳細ã¯ç¥ããªãã
é¢æ°ã®å ¥åºå
é¢æ°ã®å ¥åºåã¯ãä»ã®è¨èªã¨ã¯ã ãã¶éã£ã¦ãã¦é¢é£ããã®ã§ã¯ãªãã§ããããã次ã®é¢æ°ãèãã¾ãããã
function Out-ReceivedValues { foreach ($a in $args) { $a } foreach ($i in $input) { $i } }
ä¸è¨ã³ã¼ããã³ãã¼ãã¦ãPowershell ã³ãã³ãã©ã¤ã³ã«ãã¼ã¹ãããã¨é¢æ°ãå®ç¾©ã§ãã¾ããå®è¡ããã¨ä»¥ä¸ã®ããã§ããï¼> ã¯ãã³ãã³ãã©ã¤ã³ã®ããã³ããè¨å·ãï¼
> 1,2 | Out-ReceivedValues a b c a b c 1 2
ã³ãã³ãã©ã¤ã³å¼æ°ããã©ã¡ã¼ã¿ãããã®æååé a, b, c ã¨ããã¤ãå ¥åããã®æ´æ°é 1, 2 ããã¹ã¦åºåã«åãåºããã¾ããçµµã«æãã¨æ¬¡ã®ããã§ãã
$args 㨠$input ã¯é åï¼ãããã¯ã¤ãã¬ã¼ã¿ï¼ã§ãã$args ã«ã¯å¼æ°ããã©ã¡ã¼ã¿ãã®å¤éãå ¥ã£ã¦ããã$input ã«ã¯ãã¤ãå ¥åããã®å¤éãå ¥ã£ã¦ãã¾ããé¢æ° Out-ReceivedValues ã¯ä½ãããªãã§ãåã«åãåã£ãå¤éãåºåã«æµãã ãã§ãã
ä¸è¨ã®å ´åã«ãforeach ã«ã¼ããå±éããã¨ã次ã®ã³ã¼ããããã¯ãå®è¡ããã®ã¨åãã§ãã
{ 'a' 'b' 'c' 1 2 }
é¢æ°ã¯è¤æ°ã®æ»ãå¤ãmultiple return valuesããåºåã«è¿ãã®ã§ãå¤å¤é¢æ°ãmultiple-value functionããªã®ã§ãã
return ã¯é¢æ°ãçµäºããã¾ãããreturnæ以åã«åºåã«åãåºãããæ»ãå¤ã¯åãæ¶ãã§ãã¾ãããåä¸å¤ã ããè¿ã return ã¨ã¯çºæ³ãå ¨ç¶éãã¾ããã注æãå¿ è¦ã§ããOut-ReceivedValues ã次ã®ããã«å¤æ´ãã¦ã¿ã¾ãã
function Out-ReceivedValues { foreach ($a in $args) { $a } foreach ($i in $input) { return $i } }
å®è¡ããã¨ï¼
> 1,2 | Out-ReceivedValues a b c a b c 1
a, b, c ã¯åºåããã¾ãã1 ã return ãã¦çµããã®ã§ã2 ã¯åºåããã¾ããã
æ··ä¹±ãé¿ããããã«ã次ã®ãããªè¨èã使ãã¨è¯ããã¨æãã¾ãã
- å¼æ°ããã©ã¡ã¼ã¿ãå¤ ï¼ é å $args ã«å ¥ã£ã¦ããå¤
- ãã¤ãã©ã¤ã³å ¥åå¤ ï¼ é å $input ã«å ¥ã£ã¦ããå¤
- åãåãå¤ ï¼ å¼æ°å¤ã¾ãã¯ãã¤ãã©ã¤ã³å ¥åå¤ï¼ç·ç§°çã«ï¼
- æ»ãå¤ ï¼ åºåã«è¿ãå¤ï¼è¤æ°ããç¥ããªãï¼
é¢æ°ã®å ¥åºåã¨ãã¤ãã©ã¤ã³ã«é¢ãã¦ã¯ãjq ã彷彿ã¨ããã¾ãããããã¤ãã©ã¤ã³æåJSONå¦çããã°ã©ãã³ã°è¨èª jqãåç §ã
Powershell ã®ã³ã¼ããã¤ã©ã¤ã
ã¯ã¦ãªããã°ã§ã®è©±ã§ãããPowershell ã®ã³ã¼ããã¤ã©ã¤ããã«ã©ã¼ãªã³ã°ãã¯åºæ¥ãªãããã ã¨æã£ã¦ãã¾ãããããã°ã©ãã³ã°è¨èªåã« powershell, pwsh, ps ãªã©ãå ¥ãã¦ããã¤ã©ã¤ãããªãã£ãããã§ãã
Powershell ã®ï¼ã¯ã¦ãªããã°ã§ã®ï¼åå㯠ps1 ã§ããããªãã»ã©ãæ¡å¼µåã¨åãã ã£ãã®ããæ°ãä»ããªãã£ããã
ãã¼ãã³ã°ã³ã³ãã³ã·ã§ã³ã¨åè©
Powershell ã®é¢æ°åã¯ãåè©ã¨ç®çèªããã¤ãã³ã§ç¹ãã ååã«ãããã¨ãããã¼ãã³ã°ã³ã³ãã³ã·ã§ã³ãããã¾ãããã®ã³ã³ãã³ã·ã§ã³ãå®ããªãã¦ãåãã¾ãããè²ã ã¨ä¸é½åãã¨ãããåããããã¹ãæ©æµãåããããªããªãã®ã§å®ã£ãã»ããããã§ã*4ã
ããã«ãåè©ã«ã¯âæ¿èªããã¦ããåè©âã決ã¾ã£ã¦ãã¾ããVSCodeã®Powershellæ¡å¼µã ã¨ãâæ¿èªããã¦ããªãåè©âã使ãã¨è¦åãåºã¾ããåã¯ãMake-LogFilePath ã¨ããé¢æ°åã使ã£ãã®ã§ãããMake, Build, Create, Construct ãªã©ã®åè©ã¯æ¿èªããã¦ãªãã®ã§ãNew-LogFilePath ã«ãã¾ãããLoad, Check ãæ¿èªããã¦ãªãã®ã§æ¬¡ã®ãããªãªãã¼ã ããã¾ããã
ããLoad-SettingsFile â Read-SettingsFile
ããCheck-SettingsObject â Test-SettingsObject
æ¢åã®ã³ãã³ãã¬ããã¯ãå½ç¶ã«ãã¼ãã³ã°ã³ã³ãã³ã·ã§ã³ãå®ã£ã¦ãã¾ããGet-ChildItemï¼ls ç¸å½ï¼ãSet-Locationï¼cd ç¸å½ï¼ã¨ããæ¿èªãããåè©ã®ä¸è¦§ã¯ãã³ãã³ãã¬ãã Get-Verb ã§å¾ããã¾ããPut, Take, Peek, Lookup ã¨ããæªæ¿èªãããã¡ã¨è¾ãã
Powershell ã§ã¯ãååã®å¤§æåå°æåã¯åºå¥ããã¾ããããããµã³ãã«ã³ã¼ããVSCodeã®è£å®ãªã©ãè¦ãã¨ãé¢æ°åã¯ãã¹ã«ã«ã±ã¼ã¹ã«ããããã§ãããªã®ã§ãåããããã¦ãã¾ããNew-LogFilePath ã®ããã«ãnew-logfilepath ã¨ã NEW-LOGFILEPATH ã«ãã¦ãå®è¡ã«ã¯åé¡ããã¾ããããå¯èªæ§ãæ¤ç´¢ã§ã¯åé¡ãåºãã®ã§ããããã大æåå°æåãåºå¥ãããã®ãã¨ãæ±ã£ãã»ããç¡é£ã§ãã
ããã²ã¨ã¤ååã«é¢ãã注æäºé ã¨ãã¦ï¼ Powershell ãæåããæä¾ãã¦ããå¤æ°ï¼èªåå¤æ°ã¨ããï¼ã¨åãååããå¼æ°å¤æ°åã«ä½¿ãã¨ãã¯ãã¢ãã¤ãã¨ãèµ·ããããã§ãã以ä¸ã«æ¸ãã¦ããã¾ãã
åã®æå®
Powershell ã¯åããããæ±ãè¨èªãªã®ã§ãå¤æ°ã®åã宣è¨ãã義åã¯ããã¾ãããã¤ãããåã宣è¨ããã¡ã«ããºã ã¯æ´åããã¦ãã¾ããã
é¢æ°ã®å¼æ°ããã©ã¡ã¼ã¿ãã«å¯¾ãã¦ã¯ãåãæå®ãããã¨ãã§ãã¾ããåã¯ãåã®ååããã©ã±ããã§å²ãã å½¢å¼ã§æ¸ãã¾ãã次ã¯ãå®éã®ããã¯ã¢ããã¹ã¯ãªããå ã®é¢æ°ã®ä¾ã§ãã
function Get-SettingsFilePath([String[]] $array) { if ($array.Length -eq 0) { throw "No arg" } $first = $array[0] if (Test-Path -Path $first -PathType Leaf) { $jsonFile = $first } elseif (Test-Path -Path $first -PathType Container) { $jsonFile = Join-Path -Path $first -ChildPath $DEFAULT_SETTINGS_FILE_NAME } else { throw "File not exist" } return [String]($jsonFile) }
é¢æ° Get-SettingsFilePath ã®å¼æ° $array ã®å㯠[String[]] ã§ãããã¯æååé åã®ãã¨ã§ãã
æ»ãå¤ã®åãæå®ããæ¹æ³ã¯ããã«ã¯ããã¾ãï¼å¾è¿°ï¼ãããã¾ãå½¹ã«ç«ã¡ã¾ãããä¸è¨ã®é¢æ°ã¯åä¸æ»ãå¤ãªã®ã§ãreturn ã®ãªã㧠[String] åã§ãããã¨ã示ãã¦ãã¾ãã[String]â¥â¥ ã¨ããæ¸ãæ¹ã¯ãã£ã¹ãï¼åå¤æï¼ã®æ¸ãæ¹ãªã®ã§ãããæ»ãå¤åã®æ³¨éã¨ãã¦ä½¿ã£ã¦ãã¾ããæ»ãå¤ã«éãããé©å® [åå](â¥â¥) ã¨ãã注éï¼å®éã¯ãã£ã¹ãã ãï¼ãæãã§ããã¨ãåã追ããããã®ã容æã«ãªãã¾ãã
ãã¦ãæ»ãå¤åã®æå®ã§ããã次ã®ãããªæ¸ãæ¹ãã§ãã¾ã*5ã
function Get-Sum { [OutputType([Int32])] param([String] $a, [String] $b) return ($a + $b) }
ãã®é¢æ° Get-Sum ã¯æåååã®å¼æ°ã2ã¤åã£ã¦ãæ´æ°åãè¿ãã¨å®£è¨ããã¦ãã¾ãããããã宣è¨ã«åãã¦ãæ»ãå¤ã®åã¯æååã§ããPowershell ã®å®è¡ç³»ãã¨ã©ã¼ã«ãã¦ãããã¨æå¾ ããã®ã§ããï¼
> Get-Sum hello world helloworld
ç¹ã«ä½ãèµ·ãã¾ããï¼ã¬ã¯ãï¼ãOutputType ã®æå®ã¯ãé¢æ°ãæã¤ããããã£ã¨ãã¦ã¯ã»ããããã¦ããããã§ãã
> (Get-Command Get-Sum).OutputType Name Type TypeDefinitionAst ---- ---- ----------------- System.Int32 System.Int32
æ»ãå¤ï¼è¤æ°ããããç¥ããªãï¼ãããã³ã¨åä»ããã¦å®è¡æã«åãã§ãã¯ããã®ã¯é£ãããã§ã¯ããã¾ããåæ§ã«ããã¤ãã©ã¤ã³å ¥åå¤ã®åãã§ãã¯ã¯ã宣è¨çã«ã¯ã©ããç¡çãããé½åº¦ãã³ã¼ãå ã§äººæã§ãã§ãã¯ãããããªãããã§ãï¼ãªããã¯ã¶ãããã®ãï¼ï¼ã
ã¨ã©ã¼å¦ç
Powershell ã®ã¨ã©ã¼å¦çãã¾ã£ã¨ããªã®ã«ã¡ãã£ã¨é©ãã¾ãããã·ã§ã«ã¹ã¯ãªããè¨èªã®ã¨ã©ã¼å¦çã¨ããã¨ãbash ã®ããã« trap ã§ãããããã¦é å¼µãããã ã¨æã£ã¦ããã®ã§ã
以ä¸ã¯ãããã¯ã¢ããã¹ã¯ãªããã®ãªãã§ã® try-catch-finally ãããã¯ã§ããä¸èº«ã¯ã©ãã§ãããã®ã§ãã¨ã©ã¼å¦çæ§æã®ã¾ã£ã¨ãããæãåã£ã¦ãã ããã
try { $settingsFilePath = Get-SettingsFilePath $args $settingsObject = Read-SettingsFile $settingsFilePath $settingsObject = Test-SettingsObject $settingsObject $robocopyCommandLine = New-RobocopyCommandLine $settingsObject Write-Host $robocopyCommandLine Invoke-Expression $robocopyCommandLine } catch { Write-Host $_ Write-Host $_.ScriptStackTrace } finally { Read-Host -Prompt 'Hit Enter key' }
ä½è«ï¼ ããããã¡ã¤ã«ã«ã¦ã³ã¶ãªãã話
ããã¯ã¢ããã¹ã¯ãªããã§ã¯ãæ¥ä»æå»ãå«ããã¡ã¤ã«åã欲ããå ´é¢ãããã¾ããcmd.exe ã®å¤æ° %date%, %time% ã«æ¥ä»ã¨æå»ãæååã§å ¥ã£ã¦ãã¾ãããããã®æååãå å·¥ãã¦ãã¡ã¤ã«åãä½ãã¾ããä¾ãã°ã%date:/=-% ã¨ããã¨ãæ¥ä»æååå ã®ã¹ã©ãã·ã¥ããã¤ãã³ã«ç½®ãæãããã¨ãã§ãã¾ãã%time:~0,8% ã§ãæå»æååã®æåã®8æåãåãåºãã¾ãã
ãããå°ã£ããã¨ã«ãæ¥ä»ã¨æå»ã®æååã®ãã©ã¼ãããã¯ã·ã¹ãã ã®è¨å®*6ã§å¤ãã£ã¦ãã¾ãã¾ããè¨å®ã«ä¾åããªãå¦çãæ¸ãã¾ããããè¨å®ã¯åºå®ããã¦ãããåæã§ããããããã¡ã¤ã«å ã®æååå¦çã¯ããã¡ãªãã¦æ°æã¡æªãããããããªãã
Powershell ã® Get-Date ã³ãã³ãã¬ããã¯ã.NET ã®DateTimeåãªãã¸ã§ã¯ããè¿ãã¾ãã(Get-Date).Year ã¯ãæååã§ã¯ãªãã¦Int32åãã¼ã¿ã§ãããã¡ã¤ã«åã®çæã¯ããã©ã¼ãããæ¼ç®å -f ã使ã£ã¦ããã³ãã¬ã¼ãæååã«å¯¾ãã¦æ´æ°å¤ãã¼ã¿éãéãè¾¼ããã¨ã§éæã§ãã¾ãï¼å¤ãè¨ãæ¹ããã㨠sprintf æ¹å¼ï¼*7ã
ããããã¡ã¤ã«ã§ãtry-catch-finally æ¹å¼ã®ã¨ã©ã¼å¦çã¯ç¡çã§ããå¤é¨ã³ãã³ãã®çµäºã¹ãã¼ã¿ã¹ãã¨ã©ã¼ã¬ãã«ãã調ã¹ã¦æ¡ä»¶åå²ãããããããããããif 㨠goto ãå ¥ãä¹±ãããã¨ã«ãªãã§ãããããããããªãã
Powershellã®ã¨ã©ã¼å¦çã¯åç¯ã«ç¤ºããã¨ããã§ããã¾ã¨ãã
ãPowershell ã¹ã¯ãªãããå®è¡ããããã«ãããããã¡ã¤ã«ãä½ã£ã¦ãããã¨ããã説æãè¦ã¦ãããªãã§ãããªãã¨ãããã ï¼ãã¨æã£ãã®ã§ãããGUIã·ã§ã«ããã¡ã¤ã«ã¨ã¯ã¹ããã¼ã©ã¼ããã .ps1 ãã¡ã¤ã«ãããã«ã¯ãªãã¯ãã¦ãå®è¡ã§ããªãã¨ã®ãã¨ãããããã¡ã¤ã«ã.bat ãã¡ã¤ã«ãã¯ããã«ã¯ãªãã¯ã§å®è¡ã§ãããã¨ã
ããã«ã¯ããã®ããããã¡ã¤ã«ã [Win]+[R] ããå®è¡ããã¨ããã³ãã³ãããã³ãããcmd.exeãã¦ã£ã³ãã¦ãéãã¦ããããã¡ã¤ã«ããã©ãã°ï¼ããããããã¨ã â¥â¥ ãããã£ãã¿ããªãããªãã¨ããã®ï¼
ãã¿ã¼ããã«ã¨ã·ã§ã«ã人éã使ãUIã§ãããã¨ããèªèãã ãã ãç¡ããªã£ã¦ããã®ããç¥ããªãã
[/追è¨ã®ä½è«]
ç´åã®ã追è¨ã®ä½è«ããæ¸ããå¾ã§ãä»ã®äººã¯ã¿ã¼ããã«UIããã£ã©ã¯ã¿UIããã©ã使ã£ã¦ãã ããï¼ ã¨èå³ããã㦠Youtube æ¤ç´¢ãã¦è¦ãããcopy ã³ãã³ãã®å¼æ°ã®ãã¡ã¤ã«åããã¡ã¤ã«ã¨ã¯ã¹ããã¼ã©ã¼ã®å³ã¯ãªãã¯ããã¹ã®ã³ãã¼ããã¦ãããã¼ã¹ãã¨ãããã¡ã¤ã«ã¢ã¤ã³ã³ãã¿ã¼ããã«ã¦ã£ã³ãã¦ã«ãã©ãã°ã¨ããã¦ãã¦ãè人ã®åã¯ã¡ãã£ã¨é©ããã
ãªãã»ã©ããã¿ã¼ããã«ï¼ã·ã§ã«ã ãã使ããã£ã¦ãã¨ã¯ãã¾ããªãã¦ãããã¾ã«ä½¿ããã£ãã便å©ãªãã¼ã«ããã·ã§ã«ãªã®ãã
[/追è¨ã®ä½è« 2]
ãã®ä»ã®è¨èªæ©è½
Powershellã¹ã¯ãªããã¯ãæ¡å¼µå .ps1 ã®ãã¡ã¤ã«ã«æ¸ãã¾ããã¹ã¯ãªãããå®è¡ããã«ã¯ãä¾ãã°æ¬¡ã®ããã«ãã¾ãã
> powershell -NoProfile .\backup.ps1 .\backup-settings.json
ãããã½ã¼ã¹æ§æï¼ãããã®å¾ã«ã¹ã¯ãªãããã¡ã¤ã«åï¼ã使ãã¨ãç¾å¨å®è¡ä¸ã®ã·ã§ã«ï¼å¯¾è©±çã¤ã³ã¿ããªã¿ï¼å ã«ã¹ã¯ãªãããèªã¿è¾¼ãã§å®è¡ã§ãã¾ãããã ããå¥ããã»ã¹ã§ã®å®è¡ãæ³å®ããã¹ã¯ãªããããããã½ã¼ã¹ã§å®è¡ããã¨ãã¾ããããªããã¨ãããã¾ãã
é¢æ°ã®å®ç¾©ã ããéããã©ã¤ãã©ãªã®ãããªã¹ã¯ãªãããã¡ã¤ã«ãªããããã½ã¼ã¹ã§èªã¿è¾¼ãã§å©ç¨ã§ãã¾ãã
> . .\MyUsefulFunctions.ps1
Powershell ã«ã¯ã¢ã¸ã¥ã¼ã«ã·ã¹ãã ãããã®ã§ãã¹ã¯ãªãããã¡ã¤ã«ãã¢ã¸ã¥ã¼ã«ã«ãã¦ãã¤ã³ãã¼ããããã¨ãã§ãã¾ãã
> Import-Module MyUsefulFunctions
ã¢ã¸ã¥ã¼ã«ã«ã¡ã¿ãã¼ã¿ãä»ãããªã©ç´æã«å¾ã£ãä½æ¥ãããã¨ãããã±ã¼ã¸ã«ä»ç«ã¦ããã¨ãã§ãã¾ããããã±ã¼ã¸ã¯ãPowershellããã°ã©ã ãå ¬éã»å ±æã»é å¸ããåä½ã§ããã¤ã³ã¿ã¼ãããä¸ã®ããã±ã¼ã¸ãªãã¸ããªã»ãµã¤ãã¨ã㦠https://www.powershellgallery.com/ï¼Powershellã®ã£ã©ãªã¼ï¼ãããã¾ããããã±ã¼ã¸ç®¡çã«å¿ è¦ãªæ©è½ã¯ã³ãã³ãã¬ããã¨ãã¦ç¨æããã¦ãã¾ãã
Powershell ã§ã¯ãã¯ã©ã¹ãå®ç¾©ã§ãã¾ããã¯ã©ã¹å®ç¾©ãããã¨ã.NET ã®ã¯ã©ã¹ï¼åï¼ã¨ã ãããåãããã«æ±ãã¾ããã¯ã©ã¹ã®ãªãã¸ã§ã¯ããä½ã£ã¦ãããããã£ãã¡ã½ããã使ãããã¨ãããã¨ã§ããç¾æç¹ã§ãã¤ã³ã¿ã¼ãã§ã¤ã¹ã¯ç¡ãããã§ãã
ã¢ãã³ãªããã°ã©ãã³ã°è¨èªæ©è½ãã²ã¨éãæã£ã¦ãããã§ããããå¾æ¥ã®ã·ã§ã«ã¹ã¯ãªããè¨èªã®ã¤ã¡ã¼ã¸ï¼å°ãªãã¨ãåã®ã¤ã¡ã¼ã¸ï¼ããã¤ããããã®ã§ãã
ãã£ãããã ãã¿ããªå¤§å¥½ãã©ã ãæ½è±¡ãå¿åé¢æ° | é¢æ°ãªãã¸ã§ã¯ãããæ¸ãã¾ãã
{param($x, $y) $x + $y}
è©ä¾¡ãã¨ãã«ãããã«ã¯ãInvokeã¡ã½ãããå¼ã³ã¾ãã
> {param($x, $y) $x + $y}.Invoke(2, 3) 5
ä¸æ ¼å¥½ã§ãããå¯æãã§ããã
ãããã«
Windows OS ã«ä»å±ã® Powershell ã¯ãã¼ã¸ã§ã³5.1ãããã°ãããã¼ã¸ã§ã³ã¢ãããã¦ãã¾ãããããã¯ãã¹ãã©ãããã©ã¼ã çã®Powershellã®ææ°ã¯ .NET 9.0 ä¸ã®ãã¼ã¸ã§ã³7.5ã§ããWindows Powershell ã®Unicodeããã¹ãããã¾ãæ±ããªãã¨ããåé¡ï¼ãPowerShellã®å°ã£ã話ï¼æåã¨ã³ã³ã¼ãã£ã³ã°ãåç §ï¼ããã¯ãã¹ãã©ãããã©ã¼ã çã§ã¯è§£æ±ºããã¦ããããã§ãã
ã·ã§ã«ã¹ã¯ãªããè¨èªã¨ããæ§æ ¼ä¸ãPowershellè¨èªã¯å°å³ãªåå¨ã§ãããã¯ãã¹ãã©ãããã©ã¼ã ãªã·ã§ã«ã¹ã¯ãªããè¨èªã¨ãã¦ã®é²åã¯ç¶ç¶ãã¦ããã§ããããè¨èªä»æ§ã¯ç¾ããã¯ããã¾ããããå¤ãªè¨èªä»æ§ã«æ¹ããã人ããã£ããããã®ã§ãå°ããã¤ã¦ã¼ã¶ãå¢ãããã§ããã
*1:10å¹´ãããåã«ã¡ãã£ã¨ã¹ã¯ãªãããæ¸ãããã¨ã¯ããã¾ãããã®å½æã®è¨äº â ãPowerShellã®å°ã£ã話ï¼æåã¨ã³ã³ã¼ãã£ã³ã°ããããããããå¿ãã¾ããã
*2:UnrealEngine ã§ããã³ãã³ãã¬ããããããããã§ããã
*3:'<' ã '>' ããã㨠'|' ã¯ãã¤ãã©ã¤ã³ã§ä½¿ãã®ã§æ¼ç®åã«ã¯ä½¿ãã«ãããã¨ããäºæ ãããã¾ãã
*4:å®ããªãã¨ãï¼å®ããããªãã¨ããããã¾ãããã©ã®ãããªã¨ãã«è¦ç´ãç ´ããã¯èªåã§æ±ºãã¦ãããã»ããããã§ãããã
*5:ã¯ã©ã¹ã®ã¡ã½ããã®å ´åã¯ãã¡ã½ããåã®åã«æ»ãå¤åãæ¸ãã¾ãã
*6:intl.cpl ãèµ·åãã¦è¨å®ã§ãã¾ãã
*7:ç°¡åãªãã©ã¼ããããªããGet-Date ã ãã§ãæååãçæã§ãã¾ãã Get-Date -Format "yyyy-MM-dd HH:mm:ss" ã¨ããã¾ãã