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

Help with workflows and custom objects

$
0
0

Hi!

I want to create a script or workflow that will inventory computers C: and D: drives. I would like to use a workflow so i can query many computers simultaneously.

Unfortunately I does not get the right output. I get PSComputerName and PSSourceJobInstanceID instead of my variables.

PS C:\Windows\system32>  Get-HDDInfo -ComputerName Comp1, Comp2 

PSComputerName                                                                      PSSourceJobInstanceId                                                             
--------------                                                                      ---------------------                                                             
localhost                                                                           d7c95049-27c5-46e2-970f-7b940a656aa3                                              
localhost                                                                           d7c95049-27c5-46e2-970f-7b940a656aa3                                              
localhost                                                                           d7c95049-27c5-46e2-970f-7b940a656aa3                                              
localhost                                                                           d7c95049-27c5-46e2-970f-7b940a656aa3                                              


The Workfow!

 

Workflow Get-HDDInfo ([string[]]$ComputerName) { $Result = @() ForEach -Parallel ($Computer in $ComputerName) { $WMIComSys = Get-WmiObject -Class win32_computerSystem -Property Name -PSComputerName $Computer $WMIDiskDrives = Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID = 'C:' or DeviceID = 'D:'" -PSComputerName $Computer $tmpOBJ = New-Object psobject $tmpOBJ | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $WMIComSys.Name foreach ($DiskDrive in $WMIDiskDrives) { $VolumeLetter = ($DiskDrive.deviceID).substring(0,1) $VolumeTotalSize = "{0:N2}" -f $(($DiskDrive.Size) / 1GB) $VolumeFreeSize = "{0:N2}" -f $(($DiskDrive.FreeSpace) / 1GB) $VolumeName = $DiskDrive.VolumeName # Variables outputs the correct values to C:\_tmp\test.txt"$VolumeLetter $VolumeTotalSize $VolumeFreeSize $VolumeName" | out-file C:\_tmp\test.txt -Append $tmpOBJ | Add-Member -MemberType NoteProperty -Name "$($VolumeLetter)_VolumeName" -Value $VolumeName $tmpOBJ | Add-Member -MemberType NoteProperty -Name "$($VolumeLetter)_TotalSize" -Value $VolumeTotalSize $tmpOBJ | Add-Member -MemberType NoteProperty -Name "$($VolumeLetter)_FreeSize" -Value $VolumeFreeSize }

$workflow:Result += $tmpOBJ } return $Result }


Can anyone point me in the right direction?

Thanks!



Viewing all articles
Browse latest Browse all 21975

Trending Articles



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