fix Install-ManagementAgent script to include correct installshield switches

added Create-LocalAdmin.ps1 with base functionality
updated Tools.ps1
This commit is contained in:
2020-09-25 13:13:03 -04:00
parent 4d636246e7
commit 95abcf57c4
3 changed files with 55 additions and 2 deletions
+42
View File
@@ -0,0 +1,42 @@
#Requires -Version 5.1
param(
[Parameter(Mandatory=$true)][string]$Username,
[Parameter(Mandatory=$true)][string]$Password,
[Parameter(Mandatory=$true)][string]$FullName,
[Parameter(Mandatory=$true)][string]$Description
)
$LogName = $MyInvocation.MyCommand
Log "Securing supplied password" -Name $LogName
Try { $Password = ConvertTo-SecureString $Password -AsPlainText -Force }
Catch { $_.Exception.Message | Log -Error -Name $LogName ; Exit }
If ( IsAdmin )
{
If ( $(Get-CimInstance -ClassName Win32_OperatingSystem -Property ProductType | Select-Object -ExpandProperty ProductType) -ne "2" )
{
If ( $(Get-LocalUser -Name $User -ErrorAction SilentlyContinue) )
{
Log "Updating user: ${Username}" -Name $LogName
Try { Get-LocalUser -Name $Username | Set-LocalUser -Password $Password -FullName $FullName -Description $Description -AccountNeverExpires -PasswordNeverExpires -UserMayNotChangePassword }
Catch { $_.Exception.Message | Log -Error -Name $LogName ; Exit }
}
Else
{
Log "Creating user: ${Username}" -Name $LogName
Try { New-LocalUser -Name $Username -Password $Password -FullName $FullName -Description $Description -AccountNeverExpires -PasswordNeverExpires -UserMayNotChangePassword }
Catch { $_.Exception.Message | Log -Error -Name $LogName ; Exit }
}
If ( !($(Get-LocalGroupMember -Group "Administrators" -Member $Username -ErrorAction SilentlyContinue)) )
{
Log "Adding ""${Username}"" to local Administrators group" -Name $LogName
Try { Add-LocalGroupMember -Group "Administrators" -Member $Username }
Catch { $_.Exception.Message | Log -Error -Name $LogName ; Exit }
}
}
Else { Log "The local user account ""${User}"" cannot be created on a domain controller" -Name $LogName }
}
Else { Log "Cannot create a local user account without administrative privileges" -Name $LogName }
#Get-ChildItem "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList"
#[Environment]::Is64BitProcess