I am new to Powershell and I am trying to retrieve ipconfig /all output in an excel cell. Is it possible to get the “cmd” commands output in excel. Like ipconfig /all, net localgroup administrator. My code is mention below. Kindly help me. I want to learn PowerShell and also suggest me some good books.
Frankly, this is the hardest possible way I can think of to get a spreadsheet to contain this data.
First, I wouldn’t use IPConfig, as the output is hard to parse. I would either use native commands like Get-NetAdapter (Get-Command -Module NetAdapt*), or on older systems I might use WMI - like the Win32_NetworkAdapterConfiguration class.
Second, I’d write a script that queried all the info I needed and then assembled that into a custom object. I could then pipe that to Export-CSV and I’d get my “spreadsheet” without having to screw around with Excel. The resulting CSV would easily open in PowerShell.
If you’re likely at some point to be wanting to get this information from more than one system, and they’re all in AD, and you have access to the PS AD cmdlets, you could build a script which gets that information directly from it.
I can see that you are using the Excel object model, which limits your script to only run on machines with Excel installed on, I would replace that with the Export-CSV cmdlet.
Secondly I would not use IPConfig either because as Don Jones stated, the output is hard to parse.