2

We are going to create an image for 2000 computer and all of them will be joined to a domain trought a vpn connection.

I need to add the vpn connection, connect to it, generate a random name for the computer and then join it to a domain trought vpn.

The part where im stuck is how to generate a random name for the computer for the -NewName option. I searched for a while now but my time is short for this task and I cant afford to waste any more time with research.

Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
Richard
  • 29
  • 1
  • "can't afford to waste any more time with research" - I would recommend rephrasing. You may not have intended, but some may interpret this as saying your time is more valuable than anyone else's. – Bill_Stewart Nov 23 '16 at 17:31
  • I coded a `MakeUp-String` cmdlet a while ago where you can easily create a string and define its complexity and length, see: http://stackoverflow.com/questions/37256154/powershell-password-generator-how-to-always-include-number-in-string – iRon Nov 24 '16 at 21:10

2 Answers2

2

If you just want random letters:

-join ((65..90) + (97..122) | Get-Random -Count 10 | foreach {[char]$_})

Gives an output like:

roQZctqCEa

Change the -Count param to reflect how many letters you want.

We take a random selection of numbers in the ranges (65..90) + (97..122) then converts these to letters by using the [char] Type. The number ranges corrospond the upper and lower case letters. The returned array of letters is turned into a string by -join

If you only want Capital Letters:

-join ((65..90) | Get-Random -Count 10 | foreach {[char]$_})
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
0

I would use a Guid for that and crop everything after 13 characters:

([guid]::NewGuid()).Guid -replace '(.{13}).*', '$1'

One example output:

30284801-59e6
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172