Link to home
Start Free TrialLog in
Avatar of Netanel Elhadad
Netanel Elhadad

asked on

Get List of PC and Change Name PowerShell script

hello, i want Powershell script that give me list of all the computers in AD with the option of select one of them by number and after it i can change the computer name that i selected.

exsmple:
Get-ADComputer -Filter * -Property * | Select-Object CN
1. WS1
2. WS2
3. WS3
4. WS4
Select a PC: 2

Write-Host "Please enter your new computer name: "
$newname = Read-Host
## netdom renamecomputer $oldname /newname:$newname /userd:* /passwordd:* /usero:* /passwordo:* /reboot:10 /force
Rename-Computer -ComputerName "$oldname" -NewName "$newname" -DomainCredential amal-p\admin -Force -PassThru -Restart
SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Netanel Elhadad
Netanel Elhadad

ASKER

i add the " -Property * " and then its work perfect.

thanks a lot!!!

$pc = Get-ADComputer -Filter * -Property * | Select-Object CN |
                      Out-GridView -OutputMode Single -Title 'Select one PC to rename'
$newname = Read-Host 'Please enter your new computer name: '
Rename-Computer -ComputerName $pc.CN -NewName $newname -DomainCredential amal-p\admin -Force -PassThru -Restart
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial