I am trying to run a script to change multiple domain computer names without doing it individually. Please see my script bellow:<\/p>\n
PS C:> Start-Transcript -Path C:\\Transcript.txt<\/p>\n
PS C:> $computers = Import-CSV C:\\ClientNames.csv<\/p>\n
PS C:> $cred = Get-Credential domain\\domain admin<\/p>\n
PS C:> Foreach ($computer in $computers) {Rename-Computer -computername $computer.OldName -NewName $computer.NewName -Verbose -Force}<\/p>\n
PS C:> Stop-Transcript<\/p>\n
I am getting the following error:<\/p>\n
VERBOSE: Performing the operation “Rename-Computer” on target “computername”.
\nRename-Computer : Fail to rename computer ‘old computer name’ to ‘new computer name’ due to the following exception: Access is denied.
\nAt line:1 char:36<\/p>\n
<\/code><\/pre>\n<\/li>\n- CategoryInfo : OperationStopped: (old computer name:String) [Rename-Computer], InvalidOperationException<\/li>\n
- FullyQualifiedErrorId : FailToRenameComputer,Microsoft.PowerShell.Commands.RenameComputerCommand<\/li>\n<\/ul>\n
Any thoughts?<\/p>","upvoteCount":4,"answerCount":12,"datePublished":"2019-05-01T11:35:02.000Z","author":{"@type":"Person","name":"romankruczkowski2284","url":"https://community.spiceworks.com/u/romankruczkowski2284"},"suggestedAnswer":[{"@type":"Answer","text":"
I am trying to run a script to change multiple domain computer names without doing it individually. Please see my script bellow:<\/p>\n
PS C:> Start-Transcript -Path C:\\Transcript.txt<\/p>\n
PS C:> $computers = Import-CSV C:\\ClientNames.csv<\/p>\n
PS C:> $cred = Get-Credential domain\\domain admin<\/p>\n
PS C:> Foreach ($computer in $computers) {Rename-Computer -computername $computer.OldName -NewName $computer.NewName -Verbose -Force}<\/p>\n
PS C:> Stop-Transcript<\/p>\n
I am getting the following error:<\/p>\n
VERBOSE: Performing the operation “Rename-Computer” on target “computername”.
\nRename-Computer : Fail to rename computer ‘old computer name’ to ‘new computer name’ due to the following exception: Access is denied.
\nAt line:1 char:36<\/p>\n
\n- … computers) {Rename-Computer -computername $computer.OldName -NewName …<\/li>\n
- \n
<\/code><\/pre>\n<\/li>\n- CategoryInfo : OperationStopped: (old computer name:String) [Rename-Computer], InvalidOperationException<\/li>\n
- FullyQualifiedErrorId : FailToRenameComputer,Microsoft.PowerShell.Commands.RenameComputerCommand<\/li>\n<\/ul>\n
Any thoughts?<\/p>","upvoteCount":4,"datePublished":"2019-05-01T11:35:02.000Z","url":"https://community.spiceworks.com/t/powershell/709889/1","author":{"@type":"Person","name":"romankruczkowski2284","url":"https://community.spiceworks.com/u/romankruczkowski2284"}},{"@type":"Answer","text":"
Make sure your running the powershell session as a user with permissions to change the name or the local admin (shift + right click powershell icon, click run as different user). If you have LAPS in your environment or just have different local admin passwords and names you will need to add another field to your csv to set the credentials per machine.<\/p>","upvoteCount":0,"datePublished":"2019-05-01T11:51:24.000Z","url":"https://community.spiceworks.com/t/powershell/709889/2","author":{"@type":"Person","name":"khristopherharper","url":"https://community.spiceworks.com/u/khristopherharper"}},{"@type":"Answer","text":"
Your script gets credentials for an administrator but does not use them. Have you tried running Powershell as an account with permissions to rename the computers (Right-click > Run as)?<\/p>","upvoteCount":0,"datePublished":"2019-05-01T11:58:02.000Z","url":"https://community.spiceworks.com/t/powershell/709889/3","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"
You don’t use $cred in foreach loop with rename-computer cmdlet.<\/p>","upvoteCount":0,"datePublished":"2019-05-01T12:01:43.000Z","url":"https://community.spiceworks.com/t/powershell/709889/4","author":{"@type":"Person","name":"brankoceric","url":"https://community.spiceworks.com/u/brankoceric"}},{"@type":"Answer","text":"
Have you tried something like this?<\/p>\n
Start-Transcript -Path C:\\Transcript.txt\n$computers = Import-CSV C:\\ClientNames.csv\n$cred = Get-Credential domain\\domain admin\nForeach ($computer in $computers) {\n Rename-Computer -computername $computer.OldName -NewName $computer.NewName -DomainCredential $cred -Verbose -Force\n}\nStop-Transcript\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-05-01T12:17:34.000Z","url":"https://community.spiceworks.com/t/powershell/709889/5","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":"Obligatory PowerShell moderator comments:<\/p>\n
\n- Please use a useful subject. You’re in the PowerShell forum, so putting a subject of PowerShell is redundant
<\/li>\n - Use the code button when putting in PowerShell (it’s the </> button)<\/li>\n
- Read this: PLEASE READ BEFORE POSTING! Read if you're new to the PowerShell forum!<\/a><\/li>\n<\/ol>\n
Good luck! And I think the using of DomainCredential should do it, might need to use LocalCredential too, but probably not.<\/p>","upvoteCount":0,"datePublished":"2019-05-01T12:41:37.000Z","url":"https://community.spiceworks.com/t/powershell/709889/6","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}},{"@type":"Answer","text":"
Evan7191 This is what I get after running new script.<\/p>\n
Rename-Computer : A positional parameter cannot be found that accepts argument
\n‘System.Management.Automation.PSCredential’.
\nAt line:1 char:36<\/p>\n
\n- … computers) {Rename-Computer -computername $computer.OldName -NewName …<\/li>\n
- \n
<\/code><\/pre>\n<\/li>\n- CategoryInfo : InvalidArgument: (
[Rename-Computer], ParameterBindingException<\/li>\n - FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RenameComputerCommand<\/li>\n<\/ul>","upvoteCount":0,"datePublished":"2019-05-01T13:30:20.000Z","url":"https://community.spiceworks.com/t/powershell/709889/7","author":{"@type":"Person","name":"romankruczkowski2284","url":"https://community.spiceworks.com/u/romankruczkowski2284"}},{"@type":"Answer","text":"