Help with workflows and custom objects
hi!
i want create script or workflow inventory computers c: , d: drives. use workflow can query many computers simultaneously.
unfortunately not right output. pscomputername , pssourcejobinstanceid instead of 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 correct values 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 point me in right direction?
thanks!
hi samus-aran,
please try use using inlinescript in workflow.
for example:
workflow test-workflow { inlinescript { $obj = new-object -typename psobject $obj | add-member -membertype noteproperty ` -name exampleproperty ` -value 'hello!' $obj | get-member } } test-workflow
you can exampleproperty in output of script above.
for reasons, please refer article:
i hope helps.
Windows Server > Windows PowerShell
Comments
Post a Comment