å°ãƒã‚¿ã§ã™ã€‚
ã‚ã‚‹å ´é¢ã«ãŠã„ã¦ã€ãƒ—ãƒã‚»ã‚¹ã®å„ªå…ˆé †ä½*1 を変更ã™ã‚‹æ©Ÿä¼šãŒã‚ã‚‹ã‹ã¨æ€ã„ã¾ã™ã€‚
ãã‚“ãªæ™‚ã€è‰¯ã紹介ã•ã‚Œã¦ã„ã‚‹ã®ã¯ã€ タスクマãƒãƒ¼ã‚¸ãƒ£ãƒ¼ã‹ã‚‰ã®å„ªå…ˆåº¦ã®å¤‰æ›´ã§ã™ã。
ã—ã‹ã—ã€é•·æ™‚é–“ã®ãƒ—ãƒã‚»ã‚¹ã€ã‹ã¤å‡¦ç†ã”ã¨ã«ãƒ—ãƒã‚»ã‚¹ãŒç«‹ã¡ä¸ŠãŒã‚Šç›´ã™å ´åˆã«ã¯ã€ã‚„ã£ã¦ã‚‰ã‚Œã¾ã›ã‚“。
ã¨ã„ã†ã“ã¨ã§ã€PowerShell ã§å¤‰æ›´ã™ã‚‹æ–¹æ³•ã‚’見ã¦ã¿ã¾ã—ょã†ã€‚
プãƒã‚»ã‚¹ã®å–å¾—
ã¾ãšã¯ã€ãƒ—ãƒã‚»ã‚¹ã‚’å–å¾—ã—ã¦ã¿ã¾ã—ょã†ã€‚
Get-Process
*2ã§è¦‹ã¦ã¿ã¾ã—ょã†ã€‚
Get-Process -Name powershell | select *
ã©ã°ãƒ¼ã£ã¦ã§ã¾ã—ãŸãŒã€å¤§äº‹ãªã®ã¯PriorityClassã§ã™ã€‚
PriorityClass : Normal
全体
__NounName : Process Name : powershell Handles : 441 VM : 649650176 WS : 81375232 PM : 72654848 NPM : 26200 Path : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Company : Microsoft Corporation CPU : 1.96875 FileVersion : 6.3.9600.16384 (winblue_rtm.130821-1623) ProductVersion : 6.3.9600.16384 Description : Windows PowerShell Product : MicrosoftR WindowsR Operating System Id : 10412 PriorityClass : Normal HandleCount : 441 WorkingSet : 81375232 PagedMemorySize : 72654848 PrivateMemorySize : 72654848 VirtualMemorySize : 649650176 TotalProcessorTime : 00:00:01.9687500 BasePriority : 8 ExitCode : HasExited : False ExitTime : Handle : 4488 MachineName : . MainWindowHandle : 525428 MainWindowTitle : Windows PowerShell MainModule : System.Diagnostics.ProcessModule (powershell.exe) MaxWorkingSet : 1413120 MinWorkingSet : 204800 Modules : {System.Diagnostics.ProcessModule (powershell.exe), System.Diagnostics.ProcessModule (ntdll.dll), System.Diagnostics.ProcessModule (K ERNEL32.DLL), System.Diagnostics.ProcessModule (KERNELBASE.dll)...} NonpagedSystemMemorySize : 26200 NonpagedSystemMemorySize64 : 26200 PagedMemorySize64 : 72654848 PagedSystemMemorySize : 449832 PagedSystemMemorySize64 : 449832 PeakPagedMemorySize : 86937600 PeakPagedMemorySize64 : 86937600 PeakWorkingSet : 94642176 PeakWorkingSet64 : 94642176 PeakVirtualMemorySize : 669585408 PeakVirtualMemorySize64 : 669585408 PriorityBoostEnabled : True PrivateMemorySize64 : 72654848 PrivilegedProcessorTime : 00:00:00.4218750 ProcessName : powershell ProcessorAffinity : 255 Responding : True SessionId : 1 StartInfo : System.Diagnostics.ProcessStartInfo StartTime : 2014/02/12 4:37:15 SynchronizingObject : Threads : {7776, 9344, 1704, 13264...} UserProcessorTime : 00:00:01.5468750 VirtualMemorySize64 : 649650176 EnableRaisingEvents : False StandardInput : StandardOutput : StandardError : WorkingSet64 : 81375232 Site : Container :
PriorityClass ã‚’è¨å®šã™ã‚‹
å˜ç´”ã«ã€ã‚¿ã‚¹ã‚¯ãƒžãƒãƒ¼ã‚¸ãƒ£ãƒ¼ã§è¡¨ç¤ºã•ã‚Œã‚‹å„ªå…ˆåº¦ã‚’セットã™ã‚Œã°okã§ã™ã€‚
$ps = Get-Process -Name powershell $ps.PriorityClass = "High"
ã“ã‚Œã§ã€å„ªå…ˆåº¦ã¯å¤‰æ›´ã•ã‚Œã¾ã™ã€‚
ã•ã¦ã€ã‚‚ã†å°‘ã—良ã見ã¦ã¿ã¾ã—ょã†ã€‚
Get-Process -Name powershell | select PriorityClass | Get-Member
ã¨ã„ã†ã“ã¨ã§ã€ NoteProperty ã§ã™ã。
TypeName: Selected.System.Diagnostics.Process Name MemberType Definition ---- ---------- ---------- Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() PriorityClass NoteProperty System.Diagnostics.ProcessPriorityClass PriorityClass=Normal
ã”å˜çŸ¥ã®é€šã‚Šã€[System.Diagnostics.ProcessPriorityClass] ã¯Enumã§ã™ã€‚
[System.Diagnostics.ProcessPriorityClass]
IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True ProcessPriorityClass System.Enum
ã§ã€è¨å®šå¯èƒ½ãªå®šç¾©ãŒå…¥ã£ã¦ã„ã‚‹ã¨ã€‚
[Enum]::GetNames([System.Diagnostics.ProcessPriorityClass])
Normal Idle High RealTime BelowNormal AboveNormal
ã“ã“ã¾ã§ã‚ã‹ã£ã¦ã„ã‚Œã°ã€ã•ãã£ã¨ãƒ•ã‚¡ãƒ³ã‚¯ã‚·ãƒ§ãƒ³ã«ã—ã¾ã™ã€‚
コード
GitHub ã«ãŠã„ã¦ãŠãã¾ã™ã€‚
全文ã§ã™ã€‚
function Set-ProcessPriorityClass { [CmdletBinding()] param ( [parameter( mandatory, position = 0, valueFromPipeline, valueFromPipelineByPropertyName)] [string[]] $Name, [parameter( mandatory = 0, position = 1, valueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [System.Diagnostics.ProcessPriorityClass] $Priority, [parameter( mandatory = 0, position = 2)] [switch] $WhatIf ) begin { DATA message { ConvertFrom-StringData ` " PriorityNotChange = Process Name '{0}' Priority '{1}' was already same as Priority '{2}' you set. Skip priority change. PriorityChange = Process Name '{0}' changed Priority from '{1}' to '{2}'. ProcessNotFound = Process Name '{0}' not found. Skip priority change. " } } process { foreach ($n in $Name) { try { # Get process $ps = Get-Process | where Name -eq $n # process exist check if ($null -ne $ps) { # what if check if ($PSBoundParameters.WhatIf.IsPresent) { $Host.UI.WriteLine(("What if: " + $message.PriorityChange -f $ps.Name, $ps.PriorityClass, $Priority)) } else { # process priority check if ($ps.PriorityClass -ne $Priority) { # execute Write-Verbose ($message.PriorityChange -f $ps.Name, $ps.PriorityClass, $Priority) $ps.PriorityClass = $Priority } else { # priority want to change was same as current. Write-Verbose ($message.PriorityNotChange -f $ps.Name, $ps.PriorityClass, $Priority) } } } else { # process missing Write-Warning ($message.ProcessNotFound -f $n) } } finally { # dispose item if ($ps -ne $null){$ps.Dispose()} } } } }
利用方法
ã„ã‚ゆる PowerShellファンクションã¨ã—ã¦åˆ©ç”¨å¯èƒ½ã§ã™ã€‚ Name ã«ã¯ã€è¤‡æ•°ã®ãƒ—ãƒã‚»ã‚¹ã‚’ã¾ã¨ã‚ã¦æŒ‡å®šå¯èƒ½ã§ã™ã€‚
パラメータ指定
パラメータを指定ã—ã¦ã‚‚ã„ã„ã§ã™ã。 ã‚‚ã¡ã‚ã‚“ Priority ã¯ã€ã‚¤ãƒ³ãƒ†ãƒªã‚»ãƒ³ã‚¹ã«å€™è£œã‚‚ã§ã¾ã™ã€‚
Set-ProcessPriorityClass -Name "powershell" -Priority High -Verbose
VERBOSE: Process Name 'powershell' changed Priority from 'Normal' to 'High'.
パイプライン渡ã—
パイプラインã‹ã‚‰ã‚‚渡ã›ã¾ã™ã€‚
Get-Process | where Name -eq PowerShell | Set-ProcessPriorityClass -Priority Normal -Verbose
VERBOSE: Process Name 'powershell' changed Priority from 'High' to 'Normal'.
スプラッティング渡ã—
ã„ã‚ゆる Splatting = HashTable ã«å®šç¾©ã—ã¦æ¸¡ã™æ‰‹æ³•ã‚‚å¯èƒ½ã§ã™ã€‚
$param = @{ Name = "powershell" Priority = "High"} Set-ProcessPriorityClass @param -Verbose
VERBOSE: Process Name 'powershell' changed Priority from 'Normal' to 'High'.
WhatIf
-WhatIf
スイッãƒã‚’付ã‘ã‚‹ã“ã¨ã§ã€å®Ÿè¡Œã—ãªã„ã§ã©ã†ãªã‚‹ã‹ã‚‚事å‰ã«ç¢ºèªå¯èƒ½ã§ã™ã€‚*3
Get-Process | where Name -eq PowerShell | Set-ProcessPriorityClass -Priority Normal -Verbose -WhatIf
What if: Process Name 'powershell' changed Priority from 'High' to 'Normal'.
ã¾ã¨ã‚
ã‚ã¨ã¯ã€PSEvent ã§ã‚‚ while ã§ã‚‚ãŠå¥½ããªã‚ˆã†ã«ã‚¤ãƒ™ãƒ³ãƒˆã‚’処ç†ã—ã¦ãã ã•ã„。
ãµã ん使ã†ã“ã¨ã¯ã€ã¾ãšãªã„ã§ã™ã。