Category Archives: PowerShell and WMI

File searches with WMI

I saw a question about file searches with WMI. If you just know the file name it’s a very slow process. Painfully slow. If you have an idea about the folder its much quicker. function get-wmifile { [CmdletBinding()] param (   … Continue reading

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

user logon time

Saw an interesting question about user logon time. How can you tell the logged on user and when they logged on $logon = Get-CimInstance -ClassName Win32_LogonSession | sort StartTime -Descending | select -First 1 $user = Get-CimAssociatedInstance -InputObject $logon -ResultClassName … Continue reading

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

WMI and CIM accelerators

In PowerShell an accelerator is a shortcut to a .NET type. The WMI accelerators have been around since PowerShell v1. The WMI accelerators were heavily used in v1 fill some of the gaps in cmdlet coverage. The CIM accelerators appeared … Continue reading

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

Examples of replacing WMI cmdlet with CIM cmdlet

Following my last post I was asked about these Examples of replacing WMI cmdlet with CIM cmdlet. Example 1 gwmi win32_operatingsystem -computername $Computer -credential $creds, $cs = New-CimSession -Credential $creds -ComputerName $computer Get-CimInstance -ClassName Win32_operatingsystem -CimSession $cs Example 2 get-wmiobject … Continue reading

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

CIM not WMI

I still see a lot of people using the WMI cmdlets – Get-WmiObject etc. You really should be using CIM nit WMI. In other words use Get-CimInstance rather than get-WmiObject etc etc. Why do I say that? Two main reasons. … Continue reading

Posted in PowerShell and CIM, PowerShell and WMI | 2 Comments

Linking disks, partitions and logical drives

A question of the forums was asking about discovering disk information. They were trying to pipe the output of Get-WmiObject into another Get-WmiObject. that won’t work. There is another way. On Windows machines physical drives are divided into 1 or … Continue reading

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

Finding a CIM class

One of the problems you might find is finding a CIM class. You know its name but you don’t know which namespace its in. The old WMI cmdlets allow you to search the namespaces recursively PS> Get-WmiObject -Class Win32_Process -Namespace … Continue reading

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

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