Hello!<\/p>\n
I am building a script to ask for user input in the form of a file path which points to an excel file full of server names. I will then start a loop that, for each server in the list, gets the wmi object property “model.”<\/p>\n
The problem I am running into is that I don’t know how to properly output that data into something quick and easy. I would like the command to just spit out data inside of PowerShell with a list of all the virtual machines and their model(which can be distinguished by the model “VmWare”) and the physical machines and their model.<\/p>\n
How would you guys approach this?<\/p>\n
function Sort-VMPhysical {\n \n $AllServers = Get-Content $AllServerInput\n \n# @($AllServers) - \"C:\\Users\\bam\\Documents\\PowerShell\\Test.csv\"\n \n ForEach($server in $AllServers){\n get-wmiobject win32_computersystem -ComputerName \"$server\" | fl \"model\",\"Name\"\n \n # Write-Host \"----------\" -ForegroundColor Green\n }\n\n}\n\n$AllServerInput = Read-Host -Prompt \"Input server list filepath without quotes\"\n<\/code><\/pre>","upvoteCount":4,"answerCount":8,"datePublished":"2021-06-01T15:47:25.000Z","author":{"@type":"Person","name":"bammrm-21","url":"https://community.spiceworks.com/u/bammrm-21"},"acceptedAnswer":{"@type":"Answer","text":"there is a cmdlet called ‘group-object’<\/p>\n
$AllServerInput = Read-Host \"Input server list filepath without quotes\"\n$AllServers = Get-Content $AllServerInput\n\n$Report = \nForEach ($server in $AllServers) {\n # you should look into 'cim' instead\n get-wmiobject win32_computersystem -ComputerName \"$server\"\n}\n\n$report | select-object model,name | group-object model\n<\/code><\/pre>\ngive it a try<\/p>","upvoteCount":1,"datePublished":"2021-06-01T20:02:46.000Z","url":"https://community.spiceworks.com/t/controlling-output-in-powershell/801476/8","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hello!<\/p>\n
I am building a script to ask for user input in the form of a file path which points to an excel file full of server names. I will then start a loop that, for each server in the list, gets the wmi object property “model.”<\/p>\n
The problem I am running into is that I don’t know how to properly output that data into something quick and easy. I would like the command to just spit out data inside of PowerShell with a list of all the virtual machines and their model(which can be distinguished by the model “VmWare”) and the physical machines and their model.<\/p>\n
How would you guys approach this?<\/p>\n
function Sort-VMPhysical {\n \n $AllServers = Get-Content $AllServerInput\n \n# @($AllServers) - \"C:\\Users\\bam\\Documents\\PowerShell\\Test.csv\"\n \n ForEach($server in $AllServers){\n get-wmiobject win32_computersystem -ComputerName \"$server\" | fl \"model\",\"Name\"\n \n # Write-Host \"----------\" -ForegroundColor Green\n }\n\n}\n\n$AllServerInput = Read-Host -Prompt \"Input server list filepath without quotes\"\n<\/code><\/pre>","upvoteCount":4,"datePublished":"2021-06-01T15:47:25.000Z","url":"https://community.spiceworks.com/t/controlling-output-in-powershell/801476/1","author":{"@type":"Person","name":"bammrm-21","url":"https://community.spiceworks.com/u/bammrm-21"}},{"@type":"Answer","text":"Welcome<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n