-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompRename.ps1
51 lines (41 loc) · 1.28 KB
/
CompRename.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#####ComputerVariable#####
#Rename Computer #
#Add Domain & Restart #
# MrAmbiG #
#ambitech.blogspot.in #
##########################
function Set-PrimaryDnsSuffix {
param ([string] $Suffix)
#http://poshcode.org/2958
$ComputerNamePhysicalDnsDomain = 6
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
namespace ComputerSystem {
public class Identification {
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern bool SetComputerNameEx(int NameType, string lpBuffer);
public static bool SetPrimaryDnsSuffix(string suffix) {
try {
return SetComputerNameEx($ComputerNamePhysicalDnsDomain, suffix);
}
catch (Exception) {
return false;
}
}
}
}
"@
[ComputerSystem.Identification]::SetPrimaryDnsSuffix($Suffix)
}
#Setting Variables
$CompName = Read-Host "Enter Computer's Name"
$suffix = Read-Host "Enter Primary DNS suffix"
#Rename the Computer
Write-Host "Renaming the computer to $CompName" -foregroundcolor Green
Rename-Computer $CompName
#now set the primary dns suffix
Set-PrimaryDnsSuffix $suffix
#Reboot the Computer for the changes to take effect
Restart-Computer
#end of script