Pergunta

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?

Foi útil?

Solução 2

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.

Outras dicas

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%

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top