windows - How to assign variable names to each for loop item - Powershell -


I would like to be able to re-enable a computer (pulled through monitor) through an array of monitors And then assign each one to its own value, so that I can output results in CSV, each monitor, MFG, date, SAP, on my column.

For example:

 Monitor 1 MFG Monitor 1 SN Monitor 2 MFG Monitor 2 SN  
 Dell 12345 HP 05156  


I know how to output in the CSV already, there is a problem in facing each other's problems with their variables.

  $ monitors = get-wmiObject -namespace root \ Wmi -Class wmiMonitorID -Computer name "PC" $ monitor | % {$ I = 0} {"$ _"; $ I ++}   

This gives me every instance name of every monitor on the machine, but how do I go about grabbing serials etc

<$ p>

Good ... Here's how you will do this. It seems that wmi needs to change the data of some things into a readable form.

  $ monitor = get-WMI object-namespace root \ wmi -Class wmiMonitorID $ obj = Foreach (Monitor $ monitors) {[pscustomobject] @ {monitormf} = [four [] [$] [Monitor] Manufacturer. Name -Joined "Monitor Serial" = [four []] $ monitor. Serial Number Id- 'Monitor MFGet' = $ monitor. YEAROfManufacture}} $$ obj | Export-CSV   

Edit option ... matches the formatting you want more closely ... I think the above is better though.

  $ monitor = get-WMIObject-namespace root \ wmi -Class wmiMonitorID $ i = 1 $ obj = new object-type psobject foreach ($ monitors $ monitors) {$ obj | Add-member-name ("Monitor $ i" + "MFG") -Value ([four [] [Monitor] .ProductName -Join '') -MemberType Notepaper-Force $ OBJ | Add-member-name ("Monitor $ i" + "Serial") -Value ([four [] [$] monitor. SerialNumberID -Join '') -MemberType Notepaper-Force $ obj | Add-member-name ("Monitor $ i" + "MFGit") -Valu ($ monitor. YuanofMNAPacquery) -MemberType noteproperty- $ i ++} $$ obj | Export-CSV    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -