Terminating a running process is simply a case of calling the Terminate method: function remove-proc{ [CmdletBinding()] param ( [string]$computername = $env:COMPUTERNAME, [string]$processname ) Get-CimInstance -ClassName Win32_Process -ComputerName $computername -Filter "Name = ‘$processname’" | Invoke-CimMethod -MethodName Terminate } This will terminate all instances of a given process. If you want to be more selective then […]
Archive for January, 2014
Win32_Process examples–terminate process
Posted by: richardsiddaway | January 16, 2014 | 2 Comments |Changing the priority of a process can give a processing boost to an application – but its not always a safe option. You can modify the process like this: function set-procpriority { [CmdletBinding()] param ( [string]$computername = $env:COMPUTERNAME, [string]$processname, [ValidateSet("Idle", "BelowNormal", "Normal", "AboveNormal", "HighPriority", "RealTime")] [string]$priority ) switch ($priority){ "Idle" {[uint32]$priorityin = 64; break} "BelowNormal" […]
The first event in the 2014 Winter Scripting Games kicks off in just over 2 days time. The practice event is finished and we’re testing the judging system Good luck to all participants
Win32_Process examples: get process owner
Posted by: richardsiddaway | January 15, 2014 | No Comment |Moving on with examples of using Win32_Process you can find the process owner: function get-procowner { [CmdletBinding()] param ( [string]$computername = $env:COMPUTERNAME ) Get-CimInstance -ClassName Win32_Process -ComputerName $computername | foreach { $owner = Invoke-CimMethod -InputObject $psitem -MethodName GetOwner $props = [ordered]@{ Name = $psitem.Name Domain = $owner.Domain User = $owner.User […]
Win32_Process examples–processor time and memory usage
Posted by: richardsiddaway | January 14, 2014 | No Comment |I saw some example code for using Win32_Process and didn’t like it so decided to create my own versions. In this case the objective is to display the processor time and memory usage: function get-proctimeandRAM { [CmdletBinding()] param ( [string]$computername = $env:COMPUTERNAME ) Get-CimInstance -ClassName Win32_Process -ComputerName $computername | foreach { $props = [ordered]@{ […]
A question came into the forum about getting information on the virtual disks associated with particular Hyper-V virtual machines. Is a bit of a digging exercise but this gets the results: Get-VM | foreach { $VMname = $psitem.Name Get-VMHardDiskDrive -VMName $VMname | foreach { Get-VHD -Path $_.Path | select @{N=’VMname’; e={$VMName}}, Path, Size, […]
I saw a challenge to find the occurrences of the sequence 1759 in the larger sequence 11759171759. It was originally presented as a SQL Server based challenge to be solved with TSQL but we can do this just as easily with PowerShell using Select-String £> $data = ‘11759171759’ £> Select-String -InputObject $data -Pattern ‘1759’ -AllMatches […]
I don’t use aliases in scripts/functions and don’t use them much at the command line. One alias I do use reasonably often is gwmi for Get-WmiObject – mainly because I do a lot with WMI. I’m using the CIM cmdlets much more these days and suddenly realised that I didn’t know if they had aliases. […]
I’m currently upgrading my lab environment to Windows Server 2012 R2 which involves upgrading some machines and rebuilding the others. One task in any build or upgrade situation is to make sure that Windows is activated. Windows Server 2012 R2 will activate once an Internet connection is established. This can sometimes take a few minutes. […]
One of the freebies you get when using CDXML is that the cmdlets you create automatically get the –AsJob parameter. I was thinking about jobs in general and realised that I didn’t know how CIM jobs were run. To put this into context: PowerShell jobs run in another PowerShell process that is started as a […]
Categories
- .NET
- Active Directory
- Architecture
- Azure
- Bash
- BITS
- Books
- CDXML
- CIM
- Cloud
- COM
- Containers
- Deep Dive
- Desired State Configuration
- DevOps
- DHCP
- DNS
- DSC
- European Summit
- Events
- Exchange
- File System
- Firewall
- General
- General IT Matters
- Hyper-V
- IIS
- Infrastructure
- IT Community
- IT Security
- Learning PowerShell
- Linux
- Math
- Microsoft
- Modules
- Nano Server
- Networking
- Office 2010
- Office 2013
- Open Source
- Opinion
- Outlook
- Philosophy
- PowerShell
- PowerShell 7
- PowerShell and .NET
- PowerShell and Active Directory
- PowerShell and CIM
- PowerShell and Exchange 2007
- PowerShell and IIS
- PowerShell and SQL Server
- PowerShell and WMI
- PowerShell Basics
- PowerShell original
- PowerShell Summit
- PowerShell User Group
- PowerShell User Group 2
- PowerShell v2
- PowerShell V3
- PowerShell v4
- PowerShell v5
- PowerShell v6
- PowerShell.org
- PowerShellGet
- PowerShellV2
- PSAM
- Rant
- Registry
- Scripting
- Scripting Games
- Scripting Games 2104
- Security
- SQL Server
- Storage
- Strings
- Summit
- Technology
- Uncategorized
- Virtualization
- Windows 10
- Windows 2012 R2
- Windows 7
- Windows 8
- Windows 8 Server
- Windows 8.1
- Windows Server
- Windows server 1709
- Windows Server 2008
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016
- Windows Server 2019
- WMFv5
- WPF
- WSUS