-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewadmin.ps1
36 lines (28 loc) · 936 Bytes
/
newadmin.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
param(
[Parameter(Mandatory = $true)]
[string]$username,
[Parameter(Mandatory = $true)]
[string]$password,
[Parameter(Mandatory = $false)]
[string]$securepath = $env:ssrs_password_path
)
Write-Output "newadmin starting"
if ($username -eq "_") {
Write-Output "ERR: No SSRS user specified"
exit 1
}
if ($password -eq "_") {
if (Test-Path $securepath) {
$password = Get-Content -Raw $secretPath
}
else {
Write-Output "ERR: No SSrs user password specified and secret file not found at: $secretPath"
exit 1
}
}
$secpass = ConvertTo-SecureString -AsPlainText $password -Force
New-LocalUser "$username" -Password $secpass -FullName "$username" -Description "Local admin $username"
Add-LocalGroupMember -Group "Administrators" -Member "$username"
#net user %$username%/expires:never
Get-LocalGroupMember -Group "Administrators"
Write-Output "newadmin ended"