{"id":2109,"date":"2016-05-23T22:49:42","date_gmt":"2016-05-23T13:49:42","guid":{"rendered":"http:\/\/1bed.allright.life\/?p=2109"},"modified":"2020-04-18T21:37:35","modified_gmt":"2020-04-18T12:37:35","slug":"post-2109","status":"publish","type":"post","link":"https:\/\/1bed.allright.life\/?p=2109","title":{"rendered":"PowerShell \u5f15\u6570\u306e\u53d7\u3051\u53d6\u308a\u65b9"},"content":{"rendered":"<p>\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308b\u305f\u3081\u306e\u5ba3\u8a00\u65b9\u6cd5\u3068\u4f7f\u3044\u305d\u3046\u306a\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u5099\u5fd8\u9332<\/p>\n<h2>\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u5c5e\u6027<\/h2>\n<h3>\u57fa\u672c\u7684\u306a\u66f8\u304d\u65b9<\/h3>\n<p>\u5f15\u6570\u306f Param \u5c5e\u6027\u3092\u4f7f\u7528\u3057\u3066\u5ba3\u8a00\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  $ParameterName\n)<\/code><\/pre>\n<p>\u8907\u6570\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u5c5e\u6027\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u304d\u306f\u30ab\u30f3\u30de\u3067\u533a\u5207\u308a\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter(Argument1=value1,\n             Argument2=value2)]\n  $ParameterName\n)<\/code><\/pre>\n<h3>\u5f15\u6570\u3092\u5fc5\u9808\u306b\u3059\u308b<\/h3>\n<p>\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u5c5e\u6027\u306b\u3001Mandatory \u3092\u5ba3\u8a00\u3057\u307e\u3059<\/p>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter(Mandatory=$true)]\n  $ParameterName\n)<\/code><\/pre>\n<h3>\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u304b\u3089\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308b<\/h3>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter(ValueFromPipeline=$true)]\n  $ParameterName\n)<\/code><\/pre>\n<h2>\u5f15\u6570\u306e\u578b\u3092\u5ba3\u8a00\u3059\u308b<\/h2>\n<h3>String \u578b\u3067\u5ba3\u8a00<\/h3>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [String]\n  $ParameterName\n)<\/code><\/pre>\n<h3>Int \u578b\u3067\u5ba3\u8a00<\/h3>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [Int]\n  $ParameterName\n)<\/code><\/pre>\n<h3>Datetime \u578b\u3067\u5ba3\u8a00<\/h3>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [Datetime]\n  $ParameterName\n)<\/code><\/pre>\n<h3>String \u578b\u306e\u914d\u5217\u3067\u5ba3\u8a00<\/h3>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [String[]]\n  $ParameterName\n)<\/code><\/pre>\n<h3>Switch \u578b\u3067\u5ba3\u8a00<\/h3>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [Switch]\n  $ParameterName\n)<\/code><\/pre>\n<h2>\u5f15\u6570\u306b\u521d\u671f\u5024\u3092\u8a2d\u5b9a\u3059\u308b<\/h2>\n<h3>\u30ea\u30c6\u30e9\u30eb\u3067\u8a2d\u5b9a\u3059\u308b<\/h3>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [String]\n  $ParameterName = &#039;DefaultParameter&#039;\n)<\/code><\/pre>\n<h3>\u30b3\u30de\u30f3\u30c9\u30ec\u30c3\u30c8\u3067\u521d\u671f\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u4f8b<\/h3>\n<p>\u30bb\u30d1\u30ec\u30fc\u30bf\u30fc\u306a\u3057\u4eca\u65e5\u306e\u5e74\u6708\u65e5\u3092\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u5f15\u6570\u306b\u3059\u308b\u4f8b\u3002<\/p>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [String]\n  $ParameterName = (Get-Date -Format &#039;yyyyMMdd&#039;)\n)<\/code><\/pre>\n<h2>\u691c\u8a3c\u5c5e\u6027<\/h2>\n<h3>\u53d7\u3051\u53d6\u308b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u6570\u3092\u5236\u9650\u3059\u308b<\/h3>\n<p>1\uff5e5 \u500b\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u53d7\u3051\u53d6\u308b\u4f8b\u3002<\/p>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [ValidateCount(1,5)]\n  [String[]]\n  $ParameterName\n)<\/code><\/pre>\n<h3>\u53d7\u3051\u53d6\u308b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u6587\u5b57\u6570\u3092\u5236\u9650\u3059\u308b<\/h3>\n<p>1\uff5e5 \u6587\u5b57\u306e\u5236\u9650\u3092\u304b\u3051\u308b\u4f8b\u3002<\/p>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [ValidateLength(1,5)]\n  [String]\n  $ParameterName\n)<\/code><\/pre>\n<h3>\u53d7\u3051\u53d6\u308b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u6570\u5024\u7bc4\u56f2\u3092\u5236\u9650\u3059\u308b<\/h3>\n<p>1\uff5e5 \u3067\u5236\u9650\u3092\u304b\u3051\u308b\u4f8b\u3002<\/p>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [ValidateRange(1,5)]\n  [Int]\n  $ParameterName\n)<\/code><\/pre>\n<h3>\u6c7a\u3081\u3089\u308c\u305f\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u4ee5\u5916\u306f\u5f3e\u304f<\/h3>\n<p>Low, Middle, High \u4ee5\u5916\u306f\u5f3e\u304f\u4f8b\u3002<\/p>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [ValidateSet(&quot;Low&quot;, &quot;Middle&quot;, &quot;High&quot;)]\n  [Int]\n  $ParameterName\n)<\/code><\/pre>\n<h3>Null \u3092\u901a\u3055\u306a\u3044<\/h3>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [ValidateNotNull()]\n  $ParameterName\n)<\/code><\/pre>\n<h3>Null \u3084\u5024\u304c\u7a7a\u306f\u901a\u3055\u306a\u3044<\/h3>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [ValidateNotNullOrEmpty()]\n  $ParameterName\n)<\/code><\/pre>\n<h3>\u53d7\u3051\u53d6\u308b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u6b63\u898f\u8868\u73fe\u3067\u5236\u9650\u3059\u308b<\/h3>\n<p>3 \u6587\u5b57\u306e\u6570\u5024 + \u534a\u89d2\u30cf\u30a4\u30d5\u30f3 + 4 \u6587\u5b57\u306e\u6570\u5024\u306e\u307f\u901a\u3059\u4f8b\u3002<\/p>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [ValidatePattern(&quot;^\\d{3}\\-\\d{4}$&quot;)]\n  [String]\n  $ParameterName\n)<\/code><\/pre>\n<h3>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u304b\u3051\u308b<\/h3>\n<p>\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u3092\u304b\u3051\u308b\u4f8b\u3002<\/p>\n<pre><code class=\"language-powershell\">Param(\n  [Parameter()]\n  [ValidateScript({Test-Path -LiteralPath $_ -PathType Leaf})]\n  $ParameterName\n)<\/code><\/pre>\n<h2>\u53c2\u8003<\/h2>\n<ul>\n<li><a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/hh847743.aspx\">TechNet: about_Functions_Advanced_Parameters<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308b\u305f\u3081\u306e\u5ba3\u8a00\u65b9\u6cd5\u3068\u4f7f\u3044\u305d\u3046\u306a\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u5099\u5fd8\u9332 \u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u5c5e\u6027 \u57fa\u672c\u7684\u306a\u66f8\u304d\u65b9 \u5f15\u6570\u306f Param \u5c5e\u6027\u3092\u4f7f\u7528\u3057\u3066\u5ba3\u8a00\u3057\u307e\u3059\u3002 Param( [Parameter()] $ParameterName ) [&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-2109","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\/2109","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=2109"}],"version-history":[{"count":3,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2109\/revisions"}],"predecessor-version":[{"id":3158,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2109\/revisions\/3158"}],"wp:attachment":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}