-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddServiceAcct_to_server.ps1
66 lines (41 loc) · 1.59 KB
/
AddServiceAcct_to_server.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<#
.SYNOPSIS
add service acct to the server !!! FUN STUFF
.EXAMPLE
'one', 'two', 'three' Netwmi.ps1
.EXAMPLE
Netwmi.ps1 -computername localhost
.EXAMPLE
Netwmi.ps1 -computeername one, two, three
.EXAMPLE
get-content <ServerList.txt> or <ServerList.csv> | addservice_local_server.ps1
.PARAMETER computername
one or more computername, or IP address... peace to America!
#>
[cmdletbinding()]
Param(
[Parameter (Mandatory=$true,ValuefromPipeline=$true)]
[string []]$computername,
[string]$errorlogpath ='c:\temp\svraccterrors.log'
)
begin{}
process{
foreach ($computer in $computername) {
Write-Verbose "about to query $computer"
try {
$who = Get-WMIObject Win32_ComputerSystem -computername $computer| Select-Object -ExpandProperty name
}catch {
$computer | Out-File $errorlogpath -append
}
$Domain = Get-WmiObject -Class Win32_ComputerSystem -computername $computer
Install-WindowsFeature -Name "RSAT-AD-PowerShell"
Import-Module -Name "ActiveDirectory"
Install-ADServiceAccount -Identity "s_$env:COMPUTERNAME"
$props = @{'computername' = $computer;
'Server Name we founded :' = $who;
'DOMAIN'= $Domain.domain;}
$obj = New-Object -TypeName PSObject -Property $props
Write-Output $obj | Format-Table -AutoSize
}
}
End{}