Category Archives: PowerShell and WMI

Find the logged on user

One method of finding the logged on users is to use CIM $ComputerName = $env:COMPUTERNAME Get-CimInstance -ClassName Win32_Process -ComputerName $ComputerName -Filter “Name = ‘explorer.exe'” | foreach {         $lguser = Invoke-CimMethod -InputObject $psitem -MethodName GetOwner         $Properties = … Continue reading

Posted in PowerShell and CIM, PowerShell and WMI | Leave a comment

wmic deprecated

I saw a forum post today where the question involved the use of the wmi command line tool wmic. Wmic was deprecated in Windows Server 2012 – https://technet.microsoft.com/en-us/library/hh831568(v=ws.11).aspx. It will eventually be removed. You should use the CIM cmdlets instead … Continue reading

Posted in PowerShell and CIM, PowerShell and WMI | Leave a comment

Applying updates through WSUS

I like to keep the virtual machines in my test lab up to date so have a WSUS server to download and manage updates. The difficulty is applying the updates. With Windows 2012 R2 I used a module that would … Continue reading

Posted in PowerShell and CIM, PowerShell and WMI, Windows Server 2016, WSUS | Leave a comment

ComputerName parameters for CIM and WMI cmdlets

Accessing a remote system and running Get-WmiObject -ClassName Win32_LogicalDisk -ComputerName $computer or Get-CimInstance -ClassName Win32_LogicalDisk -ComputerName $computer is a standard approach. If you’re creating a function with that code in you may put the local machine as a default parameter: … Continue reading

Posted in PowerShell and CIM, PowerShell and WMI | Leave a comment

Working with multiple CIM objects

Many of the CIM objects we work with in our computers come in multiple instances – disks and network cards are a couple of examples. Many times when you see examples you’ll see something like this: $disks = Get-WmiObject -Class … Continue reading

Posted in PowerShell and CIM, PowerShell and WMI | Leave a comment

Server Uptime

Its easy to get the last boot time of a Windows machine but how do you get the uptime function Get-Uptime { [CmdletBinding()] param (   [string]$ComputerName = $env:COMPUTERNAME ) $os = Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $ComputerName $uptime = (Get-Date) – … Continue reading

Posted in PowerShell and CIM, PowerShell and WMI | 1 Comment

Filter early and WQL

What’s wrong with this: Get-CimInstance -ClassName Win32_Service | where {$_.State -eq ‘Running’ -and $_.StartName -notlike ‘LocalSystem’ -and $_.StartName -notlike ‘NT Authority*’} |select PSComputerName, Name, DisplayName, State, StartName Nothing except that its inefficient. if you ran this against a remote machine … Continue reading

Posted in CIM, PowerShell and CIM, PowerShell and WMI | Leave a comment