Windowes 小ネタ

:flag_jp:Japanese notation

![Windows11_icon.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3412833/b15ba9ea-c6a0-41f2-2e01-02f98d6d8136.png)


# はじめに
::: note
### 初心者対応構成
- スクリプトでの自動設定
- UCIとLuCi及びWinSCPにて比較しながら作業がおススメ
:::

::: note
### [PowerShell](https://learn.microsoft.com/ja-jp/powershell/scripting/what-is-windows-powershell?view=powershell-7.4)で[SSHアクセス](https://openwrt.org/docs/guide-quick-start/sshadministration)

- [PowerShellの開始](https://learn.microsoft.com/ja-jp/powershell/scripting/windows-powershell/starting-windows-powershell?view=powershell-7.4) (キー入力)：`Win`+`x` > `a` > `はい`
※Windows7以降標準搭載

<details><summary>パワーシェル7のインストールとショートカット作成</summary>

- PowerShell 5.1 環境でPowerShell 7のインストールとショートカット作成のスクリプト（デスクトップ）
```powershell:powershell
$currentVersion = $PSVersionTable.PSVersion
Write-Host "Current PowerShell version: $($currentVersion)"
$installed = Get-Command pwsh -ErrorAction SilentlyContinue
if ($installed) {
    Write-Host "PowerShell 7 is already installed. Skipping installation."
} else {
    Write-Host "Installing PowerShell 7..."
    $url = "https://aka.ms/install-powershell.ps1"
    Invoke-WebRequest -Uri $url -OutFile "install-powershell.ps1"
    .\install-powershell.ps1
    Write-Host "PowerShell 7 installation completed."
}
$desktop = [Environment]::GetFolderPath("Desktop")
$shortcutPath = "$desktop\PowerShell 7 (Admin).lnk"
$targetPath = "C:\Program Files\PowerShell\7\pwsh.exe"
$arguments = "-Command Start-Process pwsh -Verb runAs"
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $targetPath
$shortcut.Arguments = $arguments
$shortcut.Description = "PowerShell 7 Administrator Shortcut"
$shortcut.WorkingDirectory = "$HOME"
$shortcut.IconLocation = $targetPath
$shortcut.Save()
Write-Host "PowerShell 7 administrator shortcut has been created."

```

---

</details>

```sh
ssh root@192.168.1.1
```

<details><summary>ssh root@192.168.1.1のショートカット作成（デスクトップ）</summary>

```powershell:powershell
$DESKTOP = ([Environment]::GetFolderPath("Desktop") + "\192.168.1.1.lnk")
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$DESKTOP")
$Shortcut.TargetPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Shortcut.Arguments = '-windowstyle hidden -ExecutionPolicy RemoteSigned "Start-Process ssh root@192.168.1.1"'
$Shortcut.IconLocation = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe,0"
$Shortcut.WorkingDirectory = "."
$Shortcut.Save()

```

- `強制的に貼り付け`
- `yes`

---

</details>

<details><summary>SSHログイン出来ない場合:exclamation:</summary>

known_hostsクリア
- `C:\Users\yourusername\.ssh\known_hosts` ※Windows隠しファイル
```powershell:powershell
Clear-Content .ssh\known_hosts -Force
```
---
OpenSSHのインストール
※Windows 10 Fall Creators Update(1709)以降標準搭載
- 機能の確認
```powershell:powershell
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
```
- 機能のインストール
```powershell:powershell
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
```
---

</details>

:::
# Windows小ネタ
::: note
### バッテリーレポート
```powershell
powercfg /batteryreport

```

- ユーザー名取得
```powershell
(Get-ChildItem Env:USERNAME).Value

```
- ブラウザで起動
```powershell
C:\Windows\system32\battery-report.html
#C:\Users\"ユーザー名"\battery-report.html
```

:::

::: note
### ライセンス確認
ライセンス認証結果
```powershell
cscript "C:\Windows\System32\slmgr.vbs" /dli
```

プロダクトキー確認
```powershell
(Get-WmiObject　-query 'select * from SoftwareLicensingService').OA3xOriginalProductKey
```

ライセンス情報表示
```powershell
cscript c:\Windows\System32\slmgr.vbs  /dlv
```

全種ライセンス情報表示
```powershell
cscript c:\Windows\System32\slmgr.vbs  /dlv  all
```
:::

::: note
### 端末確認

型名
```powershell
wmic csproduct get name
```

製造番号
```powershell
wmic bios get serialnumber
```

:::

::: note
### メモリ診断ツール
```powershell
mdsched
```

:::

::: note
### Windowsエクスペリエンスインデックス
エクスペリエンス インデックス
```powershell
Get-CimInstance Win32_WinSat
```
WinSAT
```powershell
winsat formal
```
WinSAT結果
```powershell
C:\Windows\Performance\WinSAT\DataStore
```
:::

:::note
### 電源プラン「究極のパフォーマンス」

```powershell
powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61
```
:::

::: note
### SDカード 64GB以上 フォーマット

[バッファロー Disk Formatter ダウンロード](https://www.buffalo.jp/support/download/detail/?dl_contents_id=60879#1)

:::

# ソフトウェアの最新バージョンクローラー
:::note
### Serva
```powershell
$LINKS = Invoke-WebRequest "https://www.vercot.com/~serva/download.html" -UseBasicParsing
$LINKS_VERSION = $LINKS.Links | Where-Object {$_.href -like "*Serva_Community_*.zip*"} | Select-Object -ExpandProperty href
$VERSION = ($LINKS_VERSION -split '/')[-1]
Write-Host "Version to install: $VERSION"
$ONAMAE = (whoami).Split('\')[1]
$downloadPath = "C:\Users\$ONAMAE\Downloads\Serva.zip"
Invoke-WebRequest -Uri "https://www.vercot.com/~serva/download/$VERSION" -OutFile $downloadPath
$extractPath = "C:\Users\$ONAMAE\Downloads\Serva"
Expand-Archive -Path $downloadPath -DestinationPath $extractPath -Force
Remove-Item -Path $downloadPath -Force
$installPath = "C:\Program Files\Serva"
if (-not (Test-Path -Path $installPath)) { New-Item -ItemType Directory -Path $installPath -Force }
Copy-Item -Path "$extractPath\*" -Destination $installPath -Recurse -Force
Remove-Item -Path $extractPath -Recurse -Force
if ([Environment]::Is64BitOperatingSystem) { $exePath = "$installPath\Serva64.exe" } else { $exePath = "$installPath\Serva32.exe" }
$desktop = [Environment]::GetFolderPath("Desktop")
$shortcutPath = "$desktop\Serva (Admin).lnk"
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = "$exePath"
$shortcut.Arguments = ""
$shortcut.Description = "Serva Admin"
$shortcut.WorkingDirectory = "$installPath"
$shortcut.IconLocation = "$exePath,0"
$shortcut.Save()
Write-Host "Serva has been installed, and a shortcut has been created on the desktop."
```

### WinSCP
```powershell
$psVersion = $PSVersionTable.PSVersion.Major
$LINKS = Invoke-WebRequest "https://winscp.net/eng/download.php"
$LINKS_VERSION = $LINKS.Links | Where-Object {$_.href -like "*WinSCP-*-Setup.exe*"} | Select-Object -ExpandProperty href
$VERSION = ($LINKS_VERSION -split '/')[-2] -replace "WinSCP-([0-9]+\.[0-9]+\.[0-9]+).*", '$1'
Write-Host "Version to install: $VERSION"
$downloadUrl = "https://jaist.dl.sourceforge.net/project/winscp/WinSCP/$VERSION/WinSCP-$VERSION-Setup.exe?viasf=1"
Write-Host "Downloading from: $downloadUrl"
$ONAMAE = (whoami).Split('\')[1]
$destinationPath = "C:\Users\$ONAMAE\Downloads\WinSCP-$VERSION-Setup.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile $destinationPath
Write-Host "Installing WinSCP..."
Start-Process -FilePath $destinationPath -ArgumentList "/VERYSILENT /NORESTART" -Wait
Invoke-Expression "C:\Users\$ONAMAE\AppData\Local\Programs\WinSCP\WinSCP.exe"
```

:::