{"id":1488,"date":"2023-06-13T18:38:36","date_gmt":"2023-06-13T09:38:36","guid":{"rendered":"https:\/\/hi3103.net\/notes\/?p=1488"},"modified":"2024-01-28T15:49:03","modified_gmt":"2024-01-28T06:49:03","slug":"powershell-%e3%81%a71%e9%80%b1%e9%96%93%e5%88%86%e3%81%ae%e6%97%a5%e5%a0%b1%e3%82%92%e3%81%be%e3%81%a8%e3%82%81%e3%82%8b%e3%81%9f%e3%82%81%e3%81%ae-markdown-%e5%bd%a2%e5%bc%8f%e3%83%86%e3%82%ad","status":"publish","type":"post","link":"https:\/\/hi3103.net\/notes\/windows\/1488","title":{"rendered":"PowerShell \u30671\u9031\u9593\u5206\u306e\u65e5\u5831\u3092\u307e\u3068\u3081\u308b\u305f\u3081\u306e Markdown \u5f62\u5f0f\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u751f\u6210\u3059\u308b"},"content":{"rendered":"<h3>\u6982\u8981<\/h3>\n<ul>\n<li>\u696d\u52d9\u3067 Markdown \u5f62\u5f0f\u306e\u65e5\u5831\u3092\u66f8\u3044\u3066\u3044\u308b<\/li>\n<li>\u632f\u308a\u8fd4\u308a\u4f5c\u696d\u306e\u305f\u3081\u30015\u65e5\u5206\u306e\u300c\u3084\u3063\u305f\u3053\u3068\u300d\u3060\u3051\u3092\u629c\u304d\u51fa\u3057\u3066\u307e\u3068\u3081\u305f Markdown \u5f62\u5f0f\u306e <code>.md<\/code> \u30d5\u30a1\u30a4\u30eb\u3092\u6bce\u9031\u4f5c\u6210\u3057\u3066\u3044\u308b<\/li>\n<li>\u65e5\u4ed8\u306e\u898b\u51fa\u3057\u3092\u6bce\u56de\u624b\u6253\u3061\u3059\u308b\u306e\u304c\u30c0\u30eb\u304f\u306a\u3063\u3066\u304d\u305f\u306e\u3067\u3001PowerShell \u304f\u3093\u306b\u30d0\u30b7\u30c3\u3068\u4e00\u767a\u3067\u751f\u6210\u3057\u3066\u3082\u3089\u3044\u305f\u3044<\/li>\n<li>\u304b\u3064\u3001\u751f\u6210\u6e08\u307f\u306e\u5834\u5408\u306f\u3001\u8a72\u5f53\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u3067\u958b\u3044\u3066\u307b\u3057\u3044<\/li>\n<\/ul>\n<h3>\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u4f5c\u6210\u65b9\u6cd5<\/h3>\n<p><a href=\"https:\/\/openai.com\/blog\/chatgpt\">ChatGPT-4<\/a> \u306b\u4ee5\u4e0b\u306e\u624b\u9806\u3067\u3084\u3063\u3066\u3082\u3089\u3063\u305f\u3002<\/p>\n<ul>\n<li>Linux \u30d9\u30fc\u30b9\u306e OS \u3067\u52d5\u304f\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u3063\u3066\u3082\u3089\u3046<\/li>\n<li>\u3084\u308a\u305f\u3044\u3053\u3068\u3092\u4e00\u90e8\u624b\u76f4\u3057<\/li>\n<li>\u5b8c\u6210\u3057\u305f\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u3001Windows PowerShell \u7528\u306b\u5909\u63db\u3057\u3066\u3082\u3089\u3046<\/li>\n<li>\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u4fdd\u5b58\u65b9\u6cd5\u30fb\u5b9f\u884c\u65b9\u6cd5\u3092\u6559\u3048\u3066\u3082\u3089\u3046<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h3>\u5b8c\u6210\u3057\u305f\u30b9\u30af\u30ea\u30d7\u30c8<\/h3>\n<pre><code class=\"language-powershell\"># \u4eca\u65e5\u306e\u66dc\u65e5\u3092\u53d6\u5f97 (0:\u65e5\u66dc\u65e5, 1:\u6708\u66dc\u65e5, ..., 6:\u571f\u66dc\u65e5)\n$dayOfWeek = (Get-Date).DayOfWeek.value__\n\n# \u5f15\u6570\u306b\u3088\u3063\u3066\u30aa\u30d5\u30bb\u30c3\u30c8\u3092\u8abf\u6574\nswitch ($args[0]) {\n    \"prev\" {\n        if ($dayOfWeek -eq 0) {\n            $offset = -6\n        } elseif ($dayOfWeek -eq 1) {\n            $offset = -7\n        } else {\n            $offset = (1 - $dayOfWeek)\n        }\n    }\n    \"next\" {\n        if ($dayOfWeek -eq 0) {\n            $offset = 1\n        } elseif ($dayOfWeek -eq 1) {\n            $offset = 7\n        } else {\n            $offset = (8 - $dayOfWeek)\n        }\n    }\n}\n\n# \u6700\u521d\u306e\u65e5\u4ed8\u3068\u6700\u5f8c\u306e\u65e5\u4ed8\u3092\u53d6\u5f97\n$firstDay = (Get-Date).AddDays($offset)\n$lastDay = $firstDay.AddDays(6)\n\n# \u4fdd\u5b58\u5148\u3092\u5b9a\u7fa9\n$saveDir = \"C:\\Users\\hi3103\\Data\\shima\\\"\n\n# \u30d5\u30a1\u30a4\u30eb\u540d\u3092\u5b9a\u7fa9\n$filename = \"{0}_{1}.md\" -f $firstDay.ToString(\"yyyy-MM-dd\"), $lastDay.ToString(\"yyyy-MM-dd\")\n\n# \u4fdd\u5b58\u5148\u30d5\u30a1\u30a4\u30eb\u306e\u30d5\u30eb\u30d1\u30b9\u3092\u751f\u6210\n$filepath = Join-Path -Path $saveDir -ChildPath $filename\n\n# \u4f5c\u6210\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306f\u3001\u65e2\u5b58\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\nif (Test-Path -Path $filepath) {\n    Invoke-Item $filepath\n} else {\n    # \u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u30011\u884c\u76ee\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u51fa\u529b\n    Set-Content -Path $filepath -Value $filename\n\n    # 2\u884c\u76ee\u306b\u7a7a\u767d\u884c\u3092\u633f\u5165\n    Add-Content -Path $filepath -Value \"\"\n\n    # \u6307\u5b9a\u3057\u305f\u6708\u66dc\u65e5\u304b\u3089\u65e5\u66dc\u65e5\u307e\u3067\u306e\u65e5\u4ed8\u3092\u51fa\u529b (Markdown\u5f62\u5f0f\u306e\u898b\u51fa\u3057)\n    for ($i = 0; $i -le 6; $i++) {\n        $date = $firstDay.AddDays($i)\n        Add-Content -Path $filepath -Value \"# $($date.ToString(\"yyyy-MM-dd\"))\"\n    }\n\n    # \u4f5c\u6210\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\n    Invoke-Item $filepath\n}<\/code><\/pre>\n<h3>\u5b9f\u884c\u65b9\u6cd5\u30fb\u51fa\u529b\u7d50\u679c<\/h3>\n<p>PowerShell \u7528\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092 <code>nippo.sh<\/code> \u3068\u3044\u3046\u540d\u524d\u3067\u4fdd\u5b58\u3057\u305f\u3068\u4eee\u5b9a\u3002<\/p>\n<h4>\u624b\u524d\u306e\u6708\u66dc\u65e5\u30921\u65e5\u76ee\u3068\u3059\u308b\u5834\u5408<\/h4>\n<p>\u5f15\u6570 <code>prev<\/code> \u3092\u6e21\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">PowerShell -ExecutionPolicy RemoteSigned -File nippo.ps1 prev<\/code><\/pre>\n<p>\u4eee\u306b 2023-06-13\uff08\u706b\u66dc\u65e5\uff09\u306b\u5b9f\u884c\u3057\u305f\u5834\u5408\u3001\u4ee5\u4e0b\u304c\u51fa\u529b\u3055\u308c\u308b\u3002<\/p>\n<pre><code class=\"language-markdown\">2023-06-12_2023-06-18.md\n\n# 2023-06-12\n# 2023-06-13\n# 2023-06-14\n# 2023-06-15\n# 2023-06-16\n# 2023-06-17\n# 2023-06-18<\/code><\/pre>\n<h4>\u5f8c\u308d\u306e\u6708\u66dc\u65e5\u30921\u65e5\u76ee\u3068\u3059\u308b\u5834\u5408<\/h4>\n<p>\u5f15\u6570 <code>next<\/code> \u3092\u6e21\u3059\u3002<\/p>\n<pre><code class=\"language-powershell\">PowerShell -ExecutionPolicy RemoteSigned -File nippo.ps1 next<\/code><\/pre>\n<p>\u4eee\u306b 2023-06-13 \uff08\u706b\u66dc\u65e5\uff09\u306b\u5b9f\u884c\u3057\u305f\u5834\u5408\u3001\u4ee5\u4e0b\u304c\u51fa\u529b\u3055\u308c\u308b\u3002<\/p>\n<pre><code class=\"language-markdown\">2023-06-19_2023-06-25.md\n\n# 2023-06-19\n# 2023-06-20\n# 2023-06-21\n# 2023-06-22\n# 2023-06-23\n# 2023-06-24\n# 2023-06-25<\/code><\/pre>\n<h3>\u5b9f\u884c\u30b3\u30de\u30f3\u30c9\u3092\u7701\u7565\u3059\u308b<\/h3>\n<p>\u4e0b\u8a18\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u5fdc\u7528\u3057\u3001PowerShell \u7528\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u306b\u30a8\u30a4\u30ea\u30a2\u30b9\u3092\u767b\u9332\u3059\u308b\u3002<\/p>\n<blockquote>\n<p><a href=\"https:\/\/hi3103.net\/notes\/windows\/1486\">Windows Powershell \u3067\u64ec\u4f3c\u7684\u306b open \u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b &#8211; hi3103\u306e\u5099\u5fd8\u9332<\/a><\/p>\n<\/blockquote>\n<h4>\u5f15\u6570\u306e\u6271\u3044\u306b\u3064\u3044\u3066<\/h4>\n<p>\u3053\u308c\u3082 ChatGPT \u306b\u6559\u3048\u3066\u3082\u3089\u3063\u305f\u3068\u3053\u308d\u3001\u4ee5\u4e0b\u306e\u56de\u7b54\u3092\u5f97\u305f\u3002<\/p>\n<ul>\n<li><code>Set-Alias<\/code> \u30b3\u30de\u30f3\u30c9\u81ea\u4f53\u3067\u306f\u5f15\u6570\u306e\u8a2d\u5b9a\u3092\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044<\/li>\n<li>PowerShell \u95a2\u6570\u3092\u4f5c\u6210\u3059\u308c\u3070\u3001\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308b\u30a8\u30a4\u30ea\u30a2\u30b9\u3092\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u308b<\/li>\n<li>PowerShell \u95a2\u6570\u306f\u3001\u76f4\u63a5\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u308b<\/li>\n<\/ul>\n<h4>\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u306b\u8ffd\u8a18\u3059\u308b\u30bd\u30fc\u30b9<\/h4>\n<pre><code class=\"language-powershell\"># \u65e5\u5831\u307e\u3068\u3081\u4f5c\u6210\u7528\u30b3\u30de\u30f3\u30c9\nfunction nippoVars {\n    # \u5f15\u6570\u306e\u8a2d\u5b9a\n    param(\n        [Parameter(Mandatory=$false, Position=0)]\n        [string]$Arg\n    )\n\n    # \u5f15\u6570\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u3001'prev' \u307e\u305f\u306f 'next' \u3067\u306a\u3044\u5834\u5408\u306f\u51e6\u7406\u3092\u505c\u6b62\n    if ($Arg -and $Arg -notin @('prev', 'next')) {\n        Write-Host \"Invalid argument: $Arg. Expected 'prev' or 'next'.\"\n        return\n    }\n\n    # \u30b9\u30af\u30ea\u30d7\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u30d5\u30eb\u30d1\u30b9\u3067\u6307\u5b9a\n    $scriptPath = \"C:\\Users\\hi3103\\Data\\shima\\nippo.ps1\"\n\n    # \u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\n    PowerShell -ExecutionPolicy RemoteSigned -File $scriptPath $Arg\n}\n\nSet-Alias -Name nippo -Value nippoVars<\/code><\/pre>\n<h4>\u5b9f\u884c\u30b3\u30de\u30f3\u30c9<\/h4>\n<p>\u4ee5\u4e0b\u3044\u305a\u308c\u304b\u3067\u5b9f\u884c\u53ef\u80fd\u3002<\/p>\n<ul>\n<li><code>nippo<\/code><\/li>\n<li><code>nippo prev<\/code><\/li>\n<li><code>nippo next<\/code><\/li>\n<\/ul>\n<h3>\u95a2\u9023\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/h3>\n<ul>\n<li><a href=\"https:\/\/learn.microsoft.com\/ja-jp\/powershell\/scripting\/learn\/shell\/creating-profiles?view=powershell-7.3\">\u30b7\u30a7\u30eb\u74b0\u5883\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba &#8211; PowerShell | Microsoft Learn<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/ja-jp\/powershell\/module\/microsoft.powershell.core\/about\/about_profiles?view=powershell-7.3\">\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u306b\u3064\u3044\u3066 &#8211; PowerShell | Microsoft Learn<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/ja-jp\/powershell\/module\/microsoft.powershell.core\/about\/about_functions?view=powershell-7.3\">\u95a2\u6570\u306b\u3064\u3044\u3066 &#8211; PowerShell | Microsoft Learn<\/a><\/li>\n<\/ul>\n<h3>\u66f4\u65b0\u5c65\u6b74<\/h3>\n<ul>\n<li>2023-06-13 \u516c\u958b<\/li>\n<li>2024-01-28 \u30bd\u30fc\u30b9\u4fee\u6b63\u3002\u5f15\u6570\u306e\u51e6\u7406\u304c\u3046\u307e\u304f\u3044\u3063\u3066\u306a\u304b\u3063\u305f\u306e\u3067\u76f4\u3057\u305f\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 \u696d\u52d9\u3067 Markdown \u5f62\u5f0f\u306e\u65e5\u5831\u3092\u66f8\u3044\u3066\u3044\u308b \u632f\u308a\u8fd4\u308a\u4f5c\u696d\u306e\u305f\u3081\u30015\u65e5\u5206\u306e\u300c\u3084\u3063\u305f\u3053\u3068\u300d\u3060\u3051\u3092\u629c\u304d\u51fa\u3057\u3066\u307e\u3068\u3081\u305f Markdown \u5f62\u5f0f\u306e .md \u30d5\u30a1\u30a4\u30eb\u3092\u6bce\u9031\u4f5c\u6210\u3057\u3066\u3044\u308b \u65e5\u4ed8\u306e\u898b\u51fa\u3057\u3092\u6bce\u56de\u624b\u6253\u3061\u3059\u308b\u306e\u304c\u30c0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[102,84,101],"class_list":["post-1488","post","type-post","status-publish","format-standard","hentry","category-windows","tag-chatgpt","tag-markdown","tag-powershell"],"_links":{"self":[{"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/posts\/1488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/comments?post=1488"}],"version-history":[{"count":0,"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/posts\/1488\/revisions"}],"wp:attachment":[{"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/media?parent=1488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/categories?post=1488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/tags?post=1488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}