Select-Object, different output - windows

I am currently writing a script, that sends me an email, if a new Windows update gets released.
Get-WindowsUpdate
Output:
ComputerName Status KB Size Title ------------ ------ -- ---- -----
MD-I-T-092 ------- 2MB Intel - System - 4/12/2017 12:00:00 AM - 14.28.47.630
MD-I-T-092 ------- 24KB Dell Inc. - Monitor - 1/30/2018 12:00:00 AM -
MD-I-T-092 ------- 46KB Intel - System - 9/19/2017 12:00:00 AM - 11.7.0.1000
MD-I-T-092 ------- 9MB Lenovo Ltd. - Firmware - 1.0.0.50
MD-I-T-092 ------- 346KB Lenovo Ltd. - Firmware - 1.0.0.41
At the moment, only "Driver" updates are available. When a Windows update is available, I want to retrieve the "KB" Number and the "Title" of the update.
Get-WindowsUpdate | Select-Object -Property KB (or Size/Title etc.)
This method doesent work.
Output
I guess that is because the Property is not available.
Get-WindowsUpdate | Select -Property *
All Properties
As this method (https://social.technet.microsoft.com/Forums/en-US/b7e3b522-04b5-4cd5-a228-837deff9d7b8/windows-update-powershell-module-display-category-with-getwindowsupdate-aka-getwulist-cmdlet?forum=ITCG) didnt work for me, do you have any other ideas on how to filter the output?
On StackO I have not found an article that helped me, but if you know one, please let me know :)

I assume you are using the PsWindowsUpdate module.
It seems that module is poorly written and doesn't emit nice useable objects by default.
You can get at them like this:
(Get-WindowsUpdate).GetEnumerator() | Where-Object KB -ne '' | Select-Object KB, Size, Title.
Which gives output like this (assuming matching updates are found):
KB Size Title
-- ---- -----
KB5011644 697MB SQL Server 2019 RTM Cumulative Update (CU) 16 KB5011644
KB5014356 457MB Security Update for SQL Server 2019 RTM GDR (KB5014356)
KB5013887 67MB 2022-06 Cumulative Update for .NET Framework 3.5 and 4.8 for Windows 10 Version 21H2 for x64 (KB5013887)
KB2267602 789MB Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.367.1700.0)

The properties you're looking for aren't available because the Get-WindowsUpdate returns the collection of objects as a whole rather than streaming the elements one by one (like most cmdlets do). In which case, you would have been able to retrieve the individual properties from the objects.
In order to get the information you're looking for, first pipe the Get-WindowsUpdate cmdlet to the ForEach-Object cmdlet and then select your properties from there.
Get-WindowsUpdate | ForEach-Object { $_ | Select Title, KB, Size }
Here's what I get with that:

Related

Powershell - Get-Process's ProcessName is truncated on macOS

I'm using Powershell 7.2.5 on macOS 12.5.
I had Google Chrome open and ran Get-Process google*, and got truncated ProcessName:
gps google*
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
------ ----- ----- ------ -- -- -----------
0 0.00 626.36 5,529.29 33973 1 Google Chrome
0 0.00 124.94 2,870.73 33993 1 Google Chrome H
Google Chrome H should be Google Chrome Helper or something longer.
gps | sort-object {$_.ProcessName.length} showed that all processnames are truncated to 15 chars.
How do I make Get-Process output without truncation?
I read the help for Get-Process and tried to pipe the output to Format-Custom and Format-List ProcessName -Force, and none of these tricks worked.
Unfortunately, this is not a formatting problem:
At least up to the .NET version underlying PowerShell Core 7.3.0-preview.6, .NET , .NET 7.0.0-preview.6.22324.4, the .ProcessName property value is limited to 15 chars.
This is a known problem, and there is a known fix, but no one has stepped up to implement it yet - see GitHub issue #52860
A - computationally expensive - workaround is to use a call to the native ps utility, via a calculated property:
Get-Process google* |
Select-Object Id,
#{ n='ProcessName'; e={ Split-Path -Leaf (ps -p $_.Id -o comm=) }
Note: The above reports just the process ID and the (full) process name.
More work is needed if you want the same display columns as you would get by default, only with the full process names:
Get-Process google* | ForEach-Object {
$copy = $_ | Select-Object *
$copy.ProcessName = Split-Path -Leaf (ps -p $_.Id -o comm=)
$copy.pstypenames.Insert(0, 'System.Diagnostics.Process')
$copy
}

Powershell: Extract physical disk properties based on a logical drive name or a filepath [duplicate]

This question already has answers here:
Combine `Get-Disk` info and `LogicalDisk` info in PowerShell?
(3 answers)
obtain disk serial number from drive letter
(4 answers)
Closed 2 years ago.
Went through few similar queries, but could not a get a related solution as per my requirement.
Here is what I want:
I am writing a powershell script that, given a logical drive name (or a filepath), should be able to return me its underlying physical drive info like serial number, manufacturer etc.
I can get these details from Get-Disk or Get-PhysicalDisk. I see logical volume details from Get-Volume. But how do I correlate these two results to filter out results based on a specific logical volume or path (like get serial number of physical disk for the logical drive D:)
Any help is appreciated.
This is what I have tried until now:
My logical driver for which I want to get disk details:
PS C:\Users\Administrator> Get-Volume -FilePath U:\
DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining Size
----------- ------------ -------------- --------- ------------ ----------------- ------------- ----
U New Volume NTFS Fixed Healthy OK 19.91 GB 20 GB
Get-Disk has all the information I need:
PS C:\Users\Administrator> Get-Disk | Select Manufacturer, SerialNumber, UniqueId
Manufacturer SerialNumber UniqueId
------------ ------------ --------
3PARdata SGH622X73L 60002AC0000000000E006A980001AB73
3PARdata SGH622X73L 60002AC0000000000E006A990001AB73
3PARdata SGH622X73L 60002AC0000000000E006E9D0001AB73
3PARdata SGH622X73L 60002AC0000000000E006E9E0001AB73
3PARdata SGH622X73L 60002AC0000000000E006E9F0001AB73
3PARdata SGH622X73L 60002AC0000000000E006EA00001AB73
My problem is, how do I filter out which of the above listing belongs to my logical volume U:\ ?
#zett42's link worked for me. Posting it here again:
get-partition -DriveLetter U | get-disk

How to write a powershell script to know disk is basic or dynamic?

I have to check whether a given node contains any dynamic disk or not and get the list of dynamic disk using Power Shell script. I am not supposed to use diskpart command. Any other solutions other than diskpart will be appreciated.
https://social.technet.microsoft.com/Forums/windowsserver/en-US/cd7c0327-3fe9-45fc-a177-5a9927d468f3/does-the-getdisk-funtion-only-return-basic-disks?forum=winserverpowershell
Get-WmiObject Win32_DiskPartition -filter "Type='Logical Disk Manager'" | Select-Object *
you may use also diskpart utility, which is easily scriptable (I worked with it in Python)
the idea is that when you perform diskpart and then list disk,
output will be like:
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 476 GB 0 B *
So you'll see all dynamic disks marked with asterisk under "Dyn"

Powershell showing disk space details of inaccessible drives

I tried to retrieve the disk space details of a remote server A from another server B and used the below PowerShell command:
Get-WmiObject -Class Win32_LogicalDisk -ComputerName aa.bb.cc.dd -filter "DriveType=3" | Select DeviceID,#{Name="Size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},#{Name="FreeSpace(GB)";Expression={"{0:N3}" -f($_.freespace/1gb)}}
The output is as follows:
DeviceID Size(GB) FreeSpace(GB)
-------- -------- -------------
C: 59.9 17.080
D: 20.0 0.875
F: 100.0 81.865
In server A, Drive D is inaccessible. I can't see the drive space details in My computer. I checked the drive space details in Disk Management of server A and found that the above values are correct.
Again I went to server A and ran the following command in its own PowerShell window:
Get-WmiObject -Class Win32_LogicalDisk -filter "DriveType=3" | Select DeviceID,#{Name="Size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},#{Name="FreeSpace(GB)";Expression={"{0:N3}" -f($_.freespace/1gb)}} | out-file ./local.txt
Now I got the following output:
DeviceID Size(GB) FreeSpace(GB)
-------- -------- -------------
C: 59.9 17.080
D: 0.0 0.000
F: 100.0 81.864
Actually the commands are almost similar. The only difference is that if we try to get the space details of a remote machine, then we need to add the parameter -ComputerName and the remote machine name.
My question is, why is PowerShell showing two different results when I running the command remotely and locally.
The value that it is showing is actually correct.
I've a list of other servers and use this command within a script to find the disk space details of them. Tomorrow, if another drive becomes inaccessible in one of the servers, this command won't help me find it as it would retrieve its details also.

How to use WER to create a dump with the application data and the handles

Here is my registry:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps]
"DumpType"=dword:00000000
"CustomDumpFlags"=dword:00000006
According to this article DumpType=0 means custom dump and then CustomDumpFlags is taken into account. According to this article CustomDumpFlags=6 means MiniDumpWithFullMemory | MiniDumpWithHandleData, where:
MiniDumpWithFullMemory - Include all accessible memory in the process. The raw memory data is included at the end, so that the initial structures can be mapped directly without the raw memory information. This option can result in a very large file.
MiniDumpWithHandleData - Include high-level information about the operating system handles that are active when the minidump is made.
Now I have a crash-me application, so I run it, it crashes, the dump is created in %userprofile%\AppData\Local\CrashDumps, I open it in windbg and see the following line there:
User Mini Dump File with Full Memory: Only application data is
available
Which is equivalent to CustomDataFlags=2
So, how am I expected to create a dump with the handle data in it? If possible, I would like to use no third parties.
My OS is Windows 8 or Windows 2008R2 server or higher.
Try .dumpdebug, which is an undocumented command. At the top of the output there should be the flags:
0:006> .dumpdebug
----- User Mini Dump Analysis
MINIDUMP_HEADER: Version A793 (62F0) NumberOfStreams 15 Flags 41826
0002 MiniDumpWithFullMemory
0004 MiniDumpWithHandleData
0020 MiniDumpWithUnloadedModules
0800 MiniDumpWithFullMemoryInfo
1000 MiniDumpWithThreadInfo
40000 MiniDumpWithTokenInformation
If you dislike the verbose output, you can filter it with a find command on the shell:
.shell -ci ".dumpdebug" find "MiniDumpWith"

Resources