Windows/PowerShell.md
... ...
@@ -95,12 +95,17 @@ foreach( $name in ( $using_ports.Keys | sort ) ){
95 95
96 96
# 管理者権限の確認
97 97
```powershell
98
+#Requires -RunAsAdministrator
99
+```
100
+- [about_Requires - Microsoft Docs](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires)
101
+
102
+```powershell
98 103
$identity = [Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()
99
-If (-NOT $identity.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
100
- Write-Warning "管理者権限がありません。管理者として再実行してください。"
104
+If (-not $identity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
105
+ Write-Warning '管理者権限がありません。管理者として再実行してください。'
101 106
Break
102 107
}
103
-Write-Host "管理者です。"
108
+Write-Host '管理者です。'
104 109
```
105 110
- [Check for Admin Credentials in a PowerShell Script – Hey, Scripting Guy! Blog](https://blogs.technet.microsoft.com/heyscriptingguy/2011/05/11/check-for-admin-credentials-in-a-powershell-script/)
106 111
... ...
@@ -186,6 +191,25 @@ Remove-EventLog -Source "MyApp1"
186 191
# タスクスケジューラーの操作
187 192
- [ScheduledTasks](https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/)
188 193
194
+## 既存タスクの有効化/無効化
195
+```powershell
196
+# タスク有効化/無効化
197
+#Requires -RunAsAdministrator
198
+
199
+# 指定パス内の全タスクを有効化
200
+$taskPath = '\Test1\'
201
+Get-ScheduledTask -TaskPath $taskPath |
202
+ ForEach-Object { Enable-ScheduledTask -TaskPath $_.TaskPath -TaskName $_.TaskName } |
203
+ Format-Table -AutoSize
204
+
205
+# 指定タスクを無効化
206
+@(
207
+ @('\Test1\', 'テスト_コピー'),
208
+ @('\Test1\', 'テスト_バックアップ')
209
+) | ForEach-Object { Disable-ScheduledTask -TaskPath $_[0] -TaskName $_[1] } |
210
+ Format-Table -AutoSize
211
+```
212
+
189 213
# ファイアウォールの操作
190 214
- [NetSecurity](https://docs.microsoft.com/en-us/powershell/module/netsecurity/)
191 215
- [New-NetFirewallRule](https://docs.microsoft.com/en-us/powershell/module/netsecurity/New-NetFirewallRule)