Skip to content

Commit f253afd

Browse files
committed
Add ability to set computer names from scripts
1 parent 80ef024 commit f253afd

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Program.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,19 @@ static async Task Main(string[] args)
272272
else if (cmdLine.StartsWith("/computername", StringComparison.OrdinalIgnoreCase))
273273
{
274274
string name = cmdLine.Replace("/computername=", "").Trim();
275-
name = ValidateComputerName(name);
276-
277-
if (name == "")
278-
Console.WriteLine($"WARNING: Computer name \"{cmdLine.Replace("/computername=", "").Trim()}\" is not valid. Continuing with a random computer name...");
275+
if (!name.StartsWith("script:", StringComparison.OrdinalIgnoreCase))
276+
{
277+
name = ValidateComputerName(name);
279278

280-
DebugWrite($"Computer name: {name}", (debugMode | Debugger.IsAttached));
279+
if (name == "")
280+
Console.WriteLine($"WARNING: Computer name \"{cmdLine.Replace("/computername=", "").Trim()}\" is not valid. Continuing with a random computer name...");
281281

282+
DebugWrite($"Computer name: {name}", (debugMode | Debugger.IsAttached));
283+
}
284+
else
285+
{
286+
DebugWrite($"Computer name will be provided by a PowerShell script", (debugMode | Debugger.IsAttached));
287+
}
282288
computerName = name;
283289
}
284290
else if (cmdLine.StartsWith("/tzImplicit", StringComparison.OrdinalIgnoreCase))
@@ -1013,7 +1019,12 @@ Configuration.Default with
10131019
lockoutDuration: lockout.AutoUnlock) : new DisableLockoutSettings(),
10141020
PasswordExpirationSettings = (ExpirationDays == 0 ? new UnlimitedPasswordExpirationSettings() : new CustomPasswordExpirationSettings(
10151021
maxAge: ExpirationDays)),
1016-
ComputerNameSettings = randomComputerName ? new RandomComputerNameSettings() : new CustomComputerNameSettings(
1022+
ComputerNameSettings = randomComputerName ?
1023+
new RandomComputerNameSettings() :
1024+
(computerName.StartsWith("script:", StringComparison.OrdinalIgnoreCase)) ?
1025+
new ScriptComputerNameSettings(
1026+
Script: computerName.Replace("script:", "")) :
1027+
new CustomComputerNameSettings(
10171028
name: computerName),
10181029
TimeZoneSettings = timeZoneImplicit ? new ImplicitTimeZoneSettings() : new ExplicitTimeZoneSettings(
10191030
TimeZone: new TimeOffset(regionalSettings.regionTimes[0].Id, regionalSettings.regionTimes[0].DisplayName)),

UnattendGen.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
8-
<AssemblyVersion>0.6.2.2532</AssemblyVersion>
9-
<FileVersion>0.6.2.2532</FileVersion>
8+
<AssemblyVersion>0.6.2.2543</AssemblyVersion>
9+
<FileVersion>0.6.2.2543</FileVersion>
1010
<Copyright>(c) 2024-2025. CodingWonders Software, Christoph Schneegans</Copyright>
1111
</PropertyGroup>
1212
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

0 commit comments

Comments
 (0)