Rename multiple computers, after fetching data requested and save the data too

I have been trying to use the below code and it doesn’t seem to work , I get error stating “The RPC server is unavailable”

computer.csv contains 2 columns “OLDNAME” & " NEWNAME"

I’m trying to rename multiple computers however before the rename happens I want ipconfig and services info collected and saved in a text or html format.

Import-Csv -Path C:\Users\Wicky\Desktop\COMPUTERS.csv| ForEach-Object { Get-WMIObject Win32_Service -ComputerName $.OLDNAME ; Get-WMIObject Win32_process -ComputerName $.OLDNAME ;
Invoke-Command -ComputerName $.OLDNAME {systeminfo} ;Get-ADOrganizationalUnit -ComputerName $.OLDNAME ;
| Rename-Computer -DomainCredential $cred -ComputerName $.OLDNAME -NewName $.NEWNAME}|
Out-File rename.txt

could you please help editing my script to work.TIA

Hi Soma,
For Collecting Information and To do Invoke-command To Remote computers, Winrm Has To be enabled in remote computers.
enabling WinRM.

Enable-PSremoting -Force

The best way to get known about PS Remoting


The error “The RPC server is unavailable” is because you will need to enable remoting.

I’m able to restart the computer, take ps-session . remoting is enabled, still I get the error

Hi Soma,
You can try by enabling
Windows Management Instrumentation (WMI-In) in firewall inbound rule(Select proper profile-Domain, Private or All).
I was able to recreate the same by disabling it in remote machine.