Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to use function with ForEach-Object?

$
0
0
PS C:\> Get-WmiObject Win32_LogicalDisk | Where-Object -Property DriveType -eq -Value "3" | `
    ForEach-Object { $_.DeviceID, $_.FreeSpace }
C:
44025641384
D:
2816375424
E:
48146688560

Is it possible to use a function with ForEach-Object?  I know I can apply formatting, but I want to do other things based on the size of the disks while maintaining the driveletter/bytes association.  In pseudo code it might look like this

PS C:\> Get-WmiObject Win32_LogicalDisk | Where-Object -Property DriveType -eq -Value "3" | `
ForEach-Object { $_.DeviceID, $_.FreeSpace | myfunction }

C:
plenty of room
D:
ok
E:
full!



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>