0

Asking for a bit of help with my script. I would like to get a list saved to a thumb drive with the computer name and the WAN address. I know I can add a custom label with the computer name but would get the default name. I already set the computer to change the name on reboot but I do not want to reboot as there are other things that need to happen before rebooting. The computers are new and are not added to the domain. I have a thumb drive that will auto-load and assist in changing the name without asking to reboot. So other software can install.

This is what I have so far:

getmac /v /FO CSV | ConvertFrom-Csv | Select-Object @{n='ComputerName';e={$env:COMPUTERNAME}},'Physical Address','Connection Name' | Where-Object { $_.'Connection Name' -Match 'Wi-Fi' }

And this is the output:

ComputerName        Physical Address    Connection Name
------------------ ------------------ --------------------
Desktop-9K293       XX-XX-XX-XX-XX          Wi-Fi

I want the ComputerName to be the new name before rebooting. This way I can add an Export-CSV ~Location\MAC_Report.CSV -NoTypeInformation -append at the end of that code. Is there a way? Or do I need to restart the computer and generate that CSV using the same code?

I would love it to look:

ComputerName        Physical Address    Connection Name
------------------ ------------------ --------------------
NEW_____Name         XX-XX-XX-XX-XX          Wi-Fi

There are a lot of things I can make my thumb drive do. This way I have fewer restarts before adding the rest of the software(s) that also requires a restart. This way I cut my restart to one, on both all the software and computer rename.

Michael M.
  • 10,486
  • 9
  • 18
  • 34
  • 2
    Why not just manually input the computername instead of `$env:computername`? If you're renaming the computer, are you doing it through the system settings? You should be able to do it through PowerShell as well, then that way you can just pass it in a variable to the calculated property. Also, you can use: `Get-NetAdapter -Name "Wi-Fi" | Select-Object -Property Name,InterfaceDescription,MacAddress` instead. – Abraham Zinala May 14 '22 at 00:41
  • Unless you reboot, `$env:COMPUTERNAME` will always return the computers 'old' name. – Theo May 14 '22 at 14:28
  • I would have to do that to a bit over 200 computers. I want a thumb drive to gather that information into a CSV file. I can make a few thumb drives that do the same. Once my team gives me the thumb drive I can then consolidate the CSV files and pass the WLAN MAC along with next to their name to the team that handles adding them to the allow list. Trying to make this as automated as possible for human error. Also, the ```$env:computer``` is the part I would like to change to be any variable I set. I added to my code in there to see if that can be set to anything I put. – curemymind May 15 '22 at 18:07
  • Had to think for a minute as I've tried to do this here is where it just looks weird. ```getmac /v /FO CSV | ConvertFrom-Csv | Select-Object @{n='ComputerName';e={write-host NewComputername}},'Physical Address','Connection Name','Network Adapter' | Where-Object { $_.'Connection Name' -Match 'Wi-Fi' } ``` This does give me what I want but not in the output. If I can make that part work correctly I can change that to a variable of my choosing. Also, when I change computer names I use a batch script that doesn't ask for a restart until I tell it to. – curemymind May 15 '22 at 18:29

1 Answers1

0

I ended up just saving a TXT to the desktop of the computer, this way I can add the new computer name manually. This way I can then grab all the text files and consolidate them into one CSV or txt file. A bit of work but at least I can set the restart for later while I am able to install the rest of the software.

getmac /v /FO CSV | ConvertFrom-Csv | Select-Object 'Physical Address','Connection Name' | Where-Object { $_.'Connection Name' -Match 'Wi-Fi' } | Export-CSV -Path "$env:USERPROFILE\Desktop\WLAN_MAC.TXT" -NoTypeInformation

If there was a better way I would have done it.