您的位置:首页 > 运维架构 > Shell

Process in Shell

2015-12-20 19:01 561 查看
$PID    #current process
Get-Process
Get-Process | Select-Object Name
Get-Process -processname "jm" | Select-Object *
Get-Process -processname "jm" | Select-Object WorkingSet64
Stop-Process -processname baiduyunguanjia
stop-Process -Id 9556
kill -Id 9556

# help
get-help stop-process
Get-help kill
get-help Stop-Process -Examples
Get-Help kill -Online
Get-Process | Where-Object {$_.ProcessName.Contains("baiduyunguanjia") }
Get-Process | Where-Object
# special notation
# http://blog.chinaunix.net/uid-9781829-id-1997782.html 
# kill process
{$_.ProcessName.Contains("baiduyunguanjia") } | Stop-Process -CONFIRM
Get-Process | Where-Object {$_.ProcessName.Contains("baiduyunguanjia") } | Stop-Process -force

# date
Get-Date
(Get-Date).DayOfWeek

# data structure
Get-Member     # most important
Get-Help -Name # get help information
Get-Command    # command
Get-Service | Format-table
| Format-Custom
| Format-Wide
| Format-List
Get-Service | Get-Member -MemberType Property
Get-Service | format-table name, servicetype, canshutdown


# Filter
1,2,3,4 | Where-Object -FilterScript {$_ -lt 3}
Get-WmiObject -Class Win32_SystemDriver | Get-Member -MemberType Property
Get-WmiObject -Class Win32_SystemDriver | Where-Object -FilterScript {$_.State -eq "Running"}
Get-WmiObject -Class Win32_SystemDriver | Where-Object -FilterScript {$_.State -eq "Running"} | Where-Object -FilterScript {$_.StartMode -eq "Auto"}
Get-WmiObject -Class Win32_SystemDriver | Where-Object -FilterScript {$_.State -eq "Running"} | Where-Object -FilterScript {$_.StartMode -eq "Manual"} | Format-Table -Property Name,DisplayName
Get-ChildItem env:


# change file constrain
# http://www.cnblogs.com/binw/p/3921743.html Get-Acl -Path <File or Folder Path> | Format-List
# get one file's right and give it to another
Get-Acl "W:\Test\test01.txt" | Set-Acl -Path "W:\Test\test02.txt"
# WinSCP does batch processing
# http://www.cnblogs.com/binw/p/4065607.html


# a reference blog
# http://www.cnblogs.com/dreamer-fish/archive/2013/01/26/2878144.html[/code] 
# some basic operations
# remove all files in a folder
Remove-Item C:\tobedeleted –Recurse
# reborn current computer
(Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(2)
# get all child item recururse
Get-ChildItem –Force c:\directory –Recurse
Get-WmiObject -Class Win32_ComputerSystem
Get-WmiObject -Class win32_BIOS -ComputerName .
Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName .
# get current user
Get-WmiObject -Class Win32_ComputerSystem -Property UserName -ComputerName .
Get-WmiObject -Class Win32_Product -ComputerName . | Format-Wide -Column 1
# current IP address
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Format-Table -Property IPAddress
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -Property [a-z]* -ExcludeProperty IPX*,WINS*
Get-WmiObject -Class win32_networkadapterconfiguration -Filter "DHCPEnabled = true" -ComputerName .
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=true -ComputerName . | ForEach-Object -Process {$_.EnableDHCP()}


# software management
# equip MSI packet
(Get-WMIObject -ComputerName TARGETMACHINE -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install(\\MACHINEWHEREMSIRESIDES\path\package.msi)
# uplevel MSI
(Get-WmiObject -Class Win32_Product -ComputerName . -Filter "Name='name_of_app_to_be_upgraded'").Upgrade(\\MACHINEWHEREMSIRESIDES\path\upgrade_package.msi)
# remove current packet from current computer
(Get-WmiObject -Class Win32_Product -Filter "Name='product_to_remove'" -ComputerName . ).Uninstall()


# machine management
# shut down another computer after 60 seconds
Start-Sleep 60; Restart-Computer –Force –ComputerName TARGETMACHINE
# add printer
(New-Object -ComObject WScript.Network).AddWindowsPrinterConnection(\\printerserver\hplaser3)
# remove printer
(New-Object -ComObject WScript.Network).RemovePrinterConnection("\\printerserver\hplaser3 ")

EXE

> http://www.tuicool.com/articles/AbmAvq >ttp://www.cnblogs.com/dudu/archive/2011/08/23/ProcessStartInfo_bat_powershell.html
>http://club.topsage.com/thread-2134637-1-1.html
Parameter:
> http://www.pstips.net/powershell-pass-args-to-scripts.html >http://blog.vichamp.com/powershell/tip/2014/04/30/getting-arguments-from-command-line/
>http://www.pstips.net/question/4418.html
>http://www.jb51.net/article/49853.htm
>http://www.pstips.net/powershell-launching-applications.html
>http://www.jb51.net/article/53583.htm
>http://www.jb51.net/article/53065.htm
IP:
> http://www.pstips.net/get-current-ip.html > http://www.pstips.net/get-all-assigned-ip-addresses.html >http://www.cnblogs.com/dudu/archive/2011/08/23/ProcessStartInfo_bat_powershell.html
Create New Folder:
> http://blog.csdn.net/itanders/article/details/1731811 Process:
> http://stackoverflow.com/questions/651223/powershell-start-process-and-cmdline-switches
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: