{"id":2395,"date":"2016-11-26T01:41:42","date_gmt":"2016-11-25T16:41:42","guid":{"rendered":"http:\/\/1bed.allright.life\/?p=2395"},"modified":"2020-04-18T21:00:28","modified_gmt":"2020-04-18T12:00:28","slug":"post-2395","status":"publish","type":"post","link":"https:\/\/1bed.allright.life\/?p=2395","title":{"rendered":"Splatting \u304c\u4fbf\u5229"},"content":{"rendered":"<p>\u5148\u65e5 GitHub \u3067\u4ed6\u306e\u65b9\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u307f\u3066\u3044\u308b\u6642\u306b\u3053\u306e\u6a5f\u80fd\u3092\u77e5\u308a\u307e\u3057\u305f\u306e\u3067\u3001\u540c\u3058\u3088\u3046\u306b\u77e5\u3089\u306a\u3044\u4eba\u304c\u5c45\u308c\u3070\u3068\u601d\u3044\u7d39\u4ecb\u3002<\/p>\n<h2>Splatting \u3068\u306f<\/h2>\n<p>\u516c\u5f0f\u306b\u306f\u3053\u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<blockquote>\n<p>\u30b9\u30d7\u30e9\u30c3\u30c6\u30a3\u30f3\u30b0\u306f\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u5024\u306e\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u307e\u3068\u3081\u3066\u30b3\u30de\u30f3\u30c9\u306b\u6e21\u3059\u624b\u6cd5\u3067\u3059\u3002Windows PowerShell \u306f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u306e\u305d\u308c\u305e\u308c\u306e\u5024\u3092\u30b3\u30de\u30f3\u30c9\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306b\u95a2\u9023\u4ed8\u3051\u307e\u3059\u3002\u30b9\u30d7\u30e9\u30c3\u30c8\u3055\u308c\u305f\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u5024\u306f\u3001\u540d\u524d\u4ed8\u304d\u30b9\u30d7\u30e9\u30c3\u30c6\u30a3\u30f3\u30b0\u5909\u6570\u306b\u683c\u7d0d\u3055\u308c\u307e\u3059\u3002\u540d\u524d\u3064\u304d\u30b9\u30d7\u30e9\u30c3\u30c6\u30a3\u30f3\u30b0\u5909\u6570\u306f\u666e\u901a\u306e\u5909\u6570\u306e\u3088\u3046\u306b\u898b\u3048\u307e\u3059\u304c\u3001\u30c9\u30eb\u8a18\u53f7 ($) \u306e\u4ee3\u308f\u308a\u306b\u30a2\u30c3\u30c8\u30de\u30fc\u30af (@) \u3067\u59cb\u307e\u308a\u307e\u3059\u3002\u30a2\u30c3\u30c8\u30de\u30fc\u30af\u306f Windows PowerShell \u306b\u5bfe\u3057\u3066\u3001\u5f15\u6570\u304c\u5358\u4e00\u306e\u5024\u3067\u306f\u306a\u304f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3068\u3057\u3066\u6e21\u3055\u308c\u308b\u3053\u3068\u3092\u4f1d\u3048\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30d7\u30e9\u30c3\u30c6\u30a3\u30f3\u30b0\u306f\u30b3\u30de\u30f3\u30c9\u3092\u77ed\u304f\u3057\u3001\u8aad\u307f\u3084\u3059\u304f\u3057\u307e\u3059\u3002\u30b9\u30d7\u30e9\u30c3\u30c6\u30a3\u30f3\u30b0\u5024\u306f\u5225\u306e\u30b3\u30de\u30f3\u30c9\u306e\u547c\u3073\u51fa\u3057\u3067\u518d\u5229\u7528\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001\u30b9\u30d7\u30e9\u30c3\u30c6\u30a3\u30f3\u30b0\u3092\u5229\u7528\u3057\u3066\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u5024\u3092 $PSBoundParameters \u81ea\u52d5\u5909\u6570\u304b\u3089\u4ed6\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3084\u95a2\u6570\u306b\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<\/blockquote>\n<ul>\n<li><a href=\"https:\/\/technet.microsoft.com\/ja-jp\/library\/jj672955.aspx\">about_Splatting: https:\/\/technet.microsoft.com\/ja-jp\/library\/jj672955.aspx<\/a><\/li>\n<\/ul>\n<h2>\u8a18\u6cd5<\/h2>\n<p>Windows PowerShell 3.0 \u4ee5\u964d\u3067\u306f\u3001\u30b3\u30de\u30f3\u30c9\u306e\u5168\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u6b21\u306e\u3088\u3046\u306b\u8868\u305b\u308b\u305d\u3046\u3067\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">&lt;CommandName&gt; &lt;optional parameters&gt; @&lt;HashTable&gt; &lt;optional parameters&gt;\n\n&lt;CommandName&gt; &lt;optional parameters&gt; @&lt;Array&gt; &lt;optional parameters&gt;<\/code><\/pre>\n<h2>\u3088\u304f\u4f7f\u3044\u305d\u3046\u306a\u4f8b<\/h2>\n<p>\u53ef\u8aad\u6027\u304c\u826f\u304f\u306a\u308b\u306e\u3067\u4f7f\u3063\u3066\u3044\u308b\u3068\u3044\u3046\u4e8b\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u4f8b\u3048\u3070\u81ea\u4f5c\u306e\u95a2\u6570\u3067\u5f15\u6570\u304c\u591a\u3044\u3068\u304d\u3084\u3001\u6761\u4ef6\u306b\u3088\u3063\u3066\u52d5\u4f5c\u3092\u5909\u3048\u308b\u6642\u306b\u4f7f\u3044\u59cb\u3081\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306e\u95a2\u6570\u306f\u3001\u5f15\u6570\u3067 Param1, Param2, Param3 \u306b\u6570\u5024\u3092\u6e21\u3059\u3068\u8db3\u3057\u7b97\u306e\u7df4\u7fd2\uff1f\u3092\u3057\u3066\u3001-Exec \u30b9\u30a4\u30c3\u30c1\u3092\u5165\u308c\u308b\u3068\u5b9f\u969b\u306b\u8db3\u3057\u7b97\u3092\u884c\u3046\u95a2\u6570\u3067\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">function Get-ParamSum \n{\n    Param(\n        [CmdletBinding()]\n        [Parameter()]\n        [int]$Param1 = 0,\n        [Parameter()]\n        [int]$Param2 = 0,\n        [Parameter()]\n        [int]$Param3 = 0,\n        [Parameter()]\n        [switch]$Exec        \n    )\n    Write-Host -NoNewline (&#039;{0} + {1} + {2}&#039; -f $Param1, $Param2, $Param3)\n    if ($Exec) {\n        Write-Host (&#039; = {0}&#039; -f ($Param1 + $Param2 + $Param3))\n    }\n}<\/code><\/pre>\n<p>\u4f8b\u3048\u3070\u3001\u6642\u5206\u79d2\u3092\u5408\u8a08\u3057\u3066\u3001\u65e5\u4ed8\u304c\u5947\u6570\u306a\u3089 -Exec \u30b9\u30a4\u30c3\u30c1\u3092\u4ed8\u3051\u308b\u3068\u3059\u308b<\/p>\n<p>\u30c0\u30e9\u30c0\u30e9\u66f8\u3044\u3066\u307f\u305f\u4f8b<\/p>\n<pre><code class=\"language-powershell\">if(((Get-Date -UFormat %d) % 2) -eq 0) {\n    Get-ParamSum -Param1 (Get-Date -UFormat %H) -Param2 (Get-Date -UFormat %M) -Param3 (Get-Date -UFormat %S)\n} else {\n    Get-ParamSum -Param1 (Get-Date -UFormat %H) -Param2 (Get-Date -UFormat %M) -Param3 (Get-Date -UFormat %S) -Exec\n}<\/code><\/pre>\n<p>Splatting \u3092\u4f7f\u3063\u3066\u66f8\u3044\u3066\u307f\u305f\u4f8b<\/p>\n<pre><code class=\"language-powershell\">$splatting = @{\n    Param1 = Get-Date -UFormat %H\n    Param2 = Get-Date -UFormat %M\n    Param3 = Get-Date -UFormat %S\n}\n\nif(((Get-Date -UFormat %d) % 2) -eq 1) {\n    $splatting.Set_Item(&#039;Exec&#039;, $true)\n}\n\nGet-ParamSum @splatting<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u65e5 GitHub \u3067\u4ed6\u306e\u65b9\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u307f\u3066\u3044\u308b\u6642\u306b\u3053\u306e\u6a5f\u80fd\u3092\u77e5\u308a\u307e\u3057\u305f\u306e\u3067\u3001\u540c\u3058\u3088\u3046\u306b\u77e5\u3089\u306a\u3044\u4eba\u304c\u5c45\u308c\u3070\u3068\u601d\u3044\u7d39\u4ecb\u3002 Splatting \u3068\u306f \u516c\u5f0f\u306b\u306f\u3053\u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u3042\u308a\u307e\u3057\u305f\u3002 \u30b9\u30d7\u30e9\u30c3\u30c6\u30a3\u30f3\u30b0\u306f\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[62],"class_list":["post-2395","post","type-post","status-publish","format-standard","hentry","category-program","tag-powershell"],"_links":{"self":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2395"}],"version-history":[{"count":2,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2395\/revisions"}],"predecessor-version":[{"id":3137,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2395\/revisions\/3137"}],"wp:attachment":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}