0

I am trying to use a Powershell script to rename computers based on their serial numbers.

So far I have - Set-ExecutionPolicy -Unrestricted $name = (Get-WmiObject win32_bios).SerialNumber.Trim() Rename-Computer -NewName $name -DomainCredential \

I don't want this to prompt because I have a few thousand system to image and I would like this to just do the rename silently and then the MDT 2012 Update 1 will do the reboot.

I am a n00b when it comes to powershell and to scripting and I have spent the better part of a week trying to figure this out. I can get the rename to work locally with no problems but I am hoping I can get some help doing it silently.

I guess my question is, how do I put a password in my powershell script so I don't have to enter it at the workstation?

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
Fridflenstone
  • 95
  • 1
  • 5
  • 11

2 Answers2

1

I'm a little late, but couldn't you do: OSDComputerName=%serialnumber% in your task sequence rules since you're using MDT?

When the task sequence runs it should just set the computer name to that serial number. If you had a prefix or suffix like OSDComputerName=WS%SerialNumber%

jschneidereit
  • 323
  • 1
  • 6
  • For some reason when I set that my custom settings.INI it just gets ignored. As it turns out our WDS server went belly up. We will be re building the sever tomorrow and I will try this again as it will be the simplest option. – Fridflenstone May 15 '14 at 05:17
0

You can use the Get-WmiObject command let for the same and pass a password stored in a variable like below

(Get-WmiObject win32_computersystem).Rename( $NewName,$passwd,'domain\username')

to store the password in variable, you can do something like

$key = 1..32 | ForEach-Object { Get-Random -Maximum 256 }
$passwd = Read-Host "Enter password" -AsSecureString
$encpwd = ConvertFrom-SecureString $passwd -Key $key
$encpwd

This examples are taken from this post how to pass credentials to rename command?

go through this post; it explains both secure and non-secure way of storing the password in great detail.

Community
  • 1
  • 1
Rahul
  • 76,197
  • 13
  • 71
  • 125