Powershell example 2
来源:互联网 发布:million years ago知乎 编辑:程序博客网 时间:2024/06/16 11:19
ProcessCPU.ps1
#ProcessCPU.ps1$process=get-process$low=0 #counter for low cpu processes$med=0 #counter for medium cpu processes$high=0 #counter for high cpu processesforeach ($p in $process) {[int]$cpuseconds="{0:F0}" -f $p.cpu if ($cpuseconds -le 300) { write-host $p.name $cpuseconds "seconds" -foregroundcolor "Green" $low++ elseif (($cpuseconds -ge 301) -AND ($cpuseconds -le 1000)) { write-host $p.name $cpuseconds "seconds" $med++ } else { write-host $p.name $cpuseconds "seconds" -foregroundcolor "Red" $high++ }}#display a summary messagewrite-host `n"Process Summary"write-host "-->" $low "low CPU processes"write-host "-->" $med "medium CPU processes"write-host "-->" $high "high CPU processes"
SwitchRegex.ps1
#SwitchRegex.ps1$var="PowerShell123","PowerShell","123","PowerShell 123"Switch -regex ($var) {"^/w+[a-zA-Z]$" {write-host $_" is a word"}"^/d+$" {write-host $_" is a number"}"/s" {write-host $_" has a space"}Default {write-host "No match found for"$_}}
SwitchNoContinue.ps1
#SwitchNoContinue.ps1$var="PowerShell123","PowerShell","123","PowerShell 123"Switch -regex ($var) {"/w" {write-host $_" matches /w"}"/d" {write-host $_" matches /d"}"/s" {write-host $_" matches /s"}Default {write-host "No match found for"$_ }}
SwitchContinue.ps1
#SwitchContinue.ps1$var="PowerShell123","PowerShell","123","PowerShell 123"Switch -regex ($var) {"/w" {write-host $_" matches /w" ; continue}"/d" {write-host $_" matches /d" ; continue}"/s" {write-host $_" matches /s" ; continue}Default {write-host "No match found for"$_ ; }}
ServiceDemo.ps1
#ServiceDemo.ps1$services=Get-wmiobject -class "Win32_service"foreach ($svc in $services) { if (($svc.startmode -eq "Auto") -AND ($svc.state -ne "Running")) { write-host $svc.displayname $svc.state $svc.startmode ` -backgroundcolor "White" -foregroundcolor "Red" } else { write-host $svc.displayname $svc.state $svc.startmode } }$services=Get-wmiobject -class "Win32_service"foreach ($svc in $services) { if (($svc.startmode -eq "Auto") -AND ($svc.state -ne "Running")) { write-host $svc.displayname "["$svc.state"]" "["$svc.startmode"]" ` -backgroundcolor "White" -foregroundcolor "Red" } else { write-host $svc.displayname "["$svc.state"]" "["$svc.startmode"]" } }
Service2HTML.ps1
#Service2HTML.ps1# a style sheet, style.css, should be in the same directory# as the saved html file.$server=hostname$body="Services Report for "+$server.ToUpper()+"<HR>"$file="c:/"+$server+"-services.html"write-host "Generating Services Report for "$server.ToUpper()get-service |sort -property status -descending | ConvertTo-HTML `Name,DisplayName,Status -Title "Service Report" `-Head "<link rel=stylesheet type=text/css href=style.css>" `-Body $body | out-file $filewrite-host "Report Generation Complete! Open" $file "for results."
HelloForm.ps1
#HelloForm.ps1[void][Reflection.Assembly]::LoadWithPartialName(`"System.Windows.Forms")$Form = New-Object System.Windows.Forms.Form#default form size is 300x300 pixels$Form.width=250$form.height=200$Label=new-object System.Windows.Forms.Label$Label.Text="Hello World"$Label.visible=$true$Form.Text = "PowerShell TFM"$Button = New-Object System.Windows.Forms.Button$Button.Text = "OK"#set button vertical button position$Button.Top=$Form.Height*.50#default button width is 75#Center button horizontally$Button.left=($Form.Width*.50)-75/2$Button.Add_Click({$Form.Close()})$Form.Controls.Add($Button)$Form.Controls.Add($Label)$Form.ShowDialog()
HelloForm.ps1
#HelloForm.ps1[void][Reflection.Assembly]::LoadWithPartialName(`"System.Windows.Forms")$Form = New-Object System.Windows.Forms.Form#default form size is 300x300 pixels$Form.width=250$form.height=200$Label=new-object System.Windows.Forms.Label$Label.Text="Hello World"$Label.visible=$true$Form.Text = "PowerShell TFM"$Button = New-Object System.Windows.Forms.Button$Button.Text = "OK"#set button vertical button position$Button.Top=$Form.Height*.50#default button width is 75#Center button horizontally$Button.left=($Form.Width*.50)-75/2$Button.Add_Click({$Form.Close()})$Form.Controls.Add($Button)$Form.Controls.Add($Label)$Form.ShowDialog()
ServicesGrid.ps1
#ServicesGrid.ps1[void][reflection.assembly]::LoadWithPartialName(`"System.Windows.Forms")[void][reflection.assembly]::LoadWithPartialName("System.Drawing")$form = new-object System.Windows.Forms.Form$form.Size = new-object System.Drawing.Size 400,500$Form.Text = "PowerShell TFM"$DataGridView = new-object System.windows.forms.DataGridView$array= new-object System.Collections.ArrayList$data=@(get-service | write-output)$array.AddRange($data)$DataGridView.DataSource = $array$DataGridView.Dock = [System.Windows.Forms.DockStyle]::Fill$DataGridView.AllowUsertoResizeColumns=$True$form.Controls.Add($DataGridView)$form.topmost = $True$form.showdialog()
- Powershell example 2
- Powershell example 1
- Powershell example 3
- Powershell example 4
- Powershell example 5
- Powershell example 6
- PowerShell实战2:Remote_Host
- Powershell记录2
- PowerShell
- PowerShell
- PowerShell
- PowerShell
- PowerShell
- PowerShell
- PowerShell
- powershell
- Powershell
- PowerShell
- 严重:Error listenerStart
- Java web-w1:java web、jsp、JavaScript之间的区别
- Powershell example 1
- 辩证的看问题
- Redhat Enterprise Linux5安装samba服务器教程
- Powershell example 2
- 与老外打交道必知英文缩写400个
- TASK
- 今天我写了第一篇博客
- 对话框使用VIEW (转)
- 检测.net环境的C++程序
- 一些鲜为人知的编程事实
- Powershell example 3
- 7000词汇这么背我比较可以接受,连续看20天足以