{"id":1524,"date":"2024-01-28T16:26:31","date_gmt":"2024-01-28T07:26:31","guid":{"rendered":"https:\/\/hi3103.net\/notes\/?p=1524"},"modified":"2024-01-28T16:26:51","modified_gmt":"2024-01-28T07:26:51","slug":"masos-%e3%81%a7%e8%87%aa%e5%8b%95%e7%94%9f%e6%88%90%e3%81%95%e3%82%8c%e3%82%8b%e4%b8%8d%e5%8f%af%e8%a6%96%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e4%b8%80%e6%8b%ac%e5%89%8a%e9%99%a4%e3%81%99","status":"publish","type":"post","link":"https:\/\/hi3103.net\/notes\/windows\/1524","title":{"rendered":"masOS \u3067\u81ea\u52d5\u751f\u6210\u3055\u308c\u308b\u4e0d\u53ef\u8996\u30d5\u30a1\u30a4\u30eb\u3092\u4e00\u62ec\u524a\u9664\u3059\u308b PowerShell \u30b9\u30af\u30ea\u30d7\u30c8"},"content":{"rendered":"<h3>\u6982\u8981<\/h3>\n<ul>\n<li>\u9577\u5e74 Mac \u4e0a\u306e iTunes \u3067\u80b2\u3066\u3042\u3052\u305f\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u3001Windows \u306e\u307b\u3046\u3067\u5fa9\u65e7\u3055\u305b\u3088\u3046\u3068\u601d\u3044\u7acb\u3063\u305f<\/li>\n<li>\u3068\u308a\u3042\u3048\u305a SSD \u3067\u30c7\u30fc\u30bf\u3092\u4e38\u3054\u3068\u5f15\u304d\u4e0a\u3052\u305f\u3082\u306e\u306e\u3001macOS \u7279\u6709\u306e\u4e0d\u53ef\u8996\u30d5\u30a1\u30a4\u30eb\uff08.DS_store \u306a\u3069\uff09\u3082\u542b\u307e\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u307e\u305a\u306f\u3053\u308c\u3089\u306e\u304a\u6383\u9664\u3092\u305b\u306d\u3070\u3068\u306a\u3063\u305f<\/li>\n<li>\u624b\u4f5c\u696d\u3067\u884c\u3046\u306e\u306f\u7121\u7406\u306a\u91cf\u306a\u306e\u3067\u3001\u4e00\u62ec\u524a\u9664\u7528\u306e PowerShell \u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3057\u305f<\/li>\n<li>\u30bd\u30fc\u30b9\u751f\u6210\u306b\u306f ChatGPT 4 \u3092\u4f7f\u7528\u3057\u305f<\/li>\n<\/ul>\n<h3>\u4f5c\u6210\u3057\u305f\u3082\u306e<\/h3>\n<h4>\u30bd\u30fc\u30b9<\/h4>\n<pre><code class=\"language-powershell\"># masOS\u3067\u81ea\u52d5\u751f\u6210\u3055\u308c\u308b\u4e0d\u53ef\u8996\u30d5\u30a1\u30a4\u30eb\u3092\u4e00\u62ec\u524a\u9664\u3059\u308b\nfunction Set-removeMacFiles {\n    # \u73fe\u5728\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u53d6\u5f97\n    $currentDirectory = Get-Location\n\n    # \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u8a2d\u5b9a\n    $logDirectory = \"C:\\Users\\hi3103\\OneDrive\\scripts\\log\\\"\n\n    # \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u751f\u6210 (\u4f8b: \"Log_2023-10-02_12-30-00.txt\")\n    $logFileName = \"Log_\" + (Get-Date -Format \"yyyy-MM-dd_HH-mm-ss\") + \".txt\"\n    $logFilePath = Join-Path $logDirectory $logFileName\n\n    # .DS_Store \u304a\u3088\u3073 `._` \u304b\u3089\u59cb\u307e\u308b\u30d5\u30a1\u30a4\u30eb\u3092\u518d\u5e30\u7684\u306b\u691c\u7d22\u3057\u3001\u524a\u9664\n    Get-ChildItem -Path $currentDirectory -Recurse -Force -File | Where-Object {\n        $_.Name -eq \".DS_Store\" -or $_.Name -like '._*'\n    } | ForEach-Object {\n        try {\n            # -LiteralPath \u3092\u4f7f\u7528\u3057\u3066\u3001\u7279\u6b8a\u6587\u5b57\u3092\u542b\u3080\u30d1\u30b9\u3082\u6b63\u78ba\u306b\u524a\u9664\n            Remove-Item -LiteralPath $_.FullName -Force -ErrorAction Stop\n            $message = \"Deleted: \" + $_.FullName\n            # \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u8868\u793a\n            Write-Host $message\n            # \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u307f\n            Add-Content -Path $logFilePath -Value $message\n        } catch {\n            $errorMessage = \"Failed to delete: \" + $_.FullName\n            $errorDetail = $_.Exception.Message\n            # \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u30a8\u30e9\u30fc\u60c5\u5831\u3092\u8868\u793a\n            Write-Host $errorMessage -ForegroundColor Red\n            Write-Host $errorDetail -ForegroundColor Red\n            # \u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u30a8\u30e9\u30fc\u60c5\u5831\u3092\u66f8\u304d\u8fbc\u307f\n            Add-Content -Path $logFilePath -Value $errorMessage\n            Add-Content -Path $logFilePath -Value $errorDetail\n        }\n    }\n\n    # \u5b8c\u4e86\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\n    $completionMessage = \"Deletion complete. Log File: $logFilePath\"\n    Write-Host $completionMessage\n    Add-Content -Path $logFilePath -Value $completionMessage\n}\n\nNew-Alias -Name removemacfiles -Value Set-removeMacFiles<\/code><\/pre>\n<h4>\u4fdd\u5b58\u5834\u6240<\/h4>\n<pre><code>C:\\Users\\\u30e6\u30fc\u30b6\u30fc\u540d\\OneDrive\\scripts\\profile\\removeMacFiles.ps1<\/code><\/pre>\n<p>\u4e0a\u8a18\u30d5\u30a9\u30eb\u30c0\u306b\u683c\u7d0d\u3057\u305f .ps1 \u30d5\u30a1\u30a4\u30eb\u3092\u3001\u81ea\u52d5\u3067 <code>$profile<\/code> \u306b\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u3088\u3046\u8a2d\u5b9a\u3057\u3066\u3042\u308b\u3002<\/p>\n<p>\u203b\u53c2\u8003\uff1a<a href=\"https:\/\/hi3103.net\/notes\/windows\/1526\">PowerShell \u30b9\u30af\u30ea\u30d7\u30c8\u3092 OneDrive \u306e\u4e2d\u3067\u7ba1\u7406\u3059\u308b<\/a><\/p>\n<h4>\u4f7f\u3044\u65b9<\/h4>\n<ol>\n<li>PowerShell \u3092\u958b\u304f<\/li>\n<li>\u524a\u9664\u3057\u305f\u3044\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5<\/li>\n<li><code>removemacfiles<\/code> \u3068\u5165\u529b\u3057\u3066\u5b9f\u884c<\/li>\n<li>\u30ed\u30b0\u3092\u78ba\u8a8d\n<ul>\n<li>\u554f\u984c\u306a\u3055\u305d\u3046\u306a\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u3082\u5931\u6557\u3059\u308b\u5834\u5408\u304c\u3042\u308b<\/li>\n<li>\u305d\u3046\u3044\u3046\u306e\u306f\u8ae6\u3081\u3066\u624b\u52d5\u3067\u524a\u9664\u3059\u308b<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 \u9577\u5e74 Mac \u4e0a\u306e iTunes \u3067\u80b2\u3066\u3042\u3052\u305f\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u3001Windows \u306e\u307b\u3046\u3067\u5fa9\u65e7\u3055\u305b\u3088\u3046\u3068\u601d\u3044\u7acb\u3063\u305f \u3068\u308a\u3042\u3048\u305a SSD \u3067\u30c7\u30fc\u30bf\u3092\u4e38\u3054\u3068\u5f15\u304d\u4e0a\u3052\u305f\u3082\u306e\u306e\u3001macOS \u7279\u6709\u306e\u4e0d\u53ef\u8996\u30d5\u30a1\u30a4\u30eb\uff08.DS_stor [&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":[101],"class_list":["post-1524","post","type-post","status-publish","format-standard","hentry","category-windows","tag-powershell"],"_links":{"self":[{"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/posts\/1524","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=1524"}],"version-history":[{"count":0,"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/posts\/1524\/revisions"}],"wp:attachment":[{"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/media?parent=1524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/categories?post=1524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hi3103.net\/notes\/wp-json\/wp\/v2\/tags?post=1524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}