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
+1 -1
View File
@@ -58,7 +58,7 @@ If ( $CUSTOMER_ID -and $TOKEN )
## Install the agent ## Install the agent
Write-Log "Begin installing agent" Write-Log "Begin installing agent"
Try { Start-Process $AGENT_INSTALLER -ArgumentList "/s /v /qn CUSTOMERID=${CUSTOMER_ID} CUSTOMERSPECIFIC=1 REGISTRATION_TOKEN=${TOKEN} SERVERPROTOCOL=HTTPS SERVERADDRESS=${SERVER} SERVERPORT=443" -Wait } Try { Start-Process $AGENT_INSTALLER -ArgumentList "/s /v "" /qn CUSTOMERID=${CUSTOMER_ID} CUSTOMERSPECIFIC=1 REGISTRATION_TOKEN=${TOKEN} SERVERPROTOCOL=HTTPS SERVERADDRESS=${SERVER} SERVERPORT=443 """ -Wait }
Catch { Write-Log $_.Exception.Message } Catch { Write-Log $_.Exception.Message }
## Remove the agent installer ## Remove the agent installer
+11
View File
@@ -206,3 +206,14 @@ switch ($PSCmdlet.ParameterSetName)
'eq' { If ( $WindowsBuild -eq $eq ) { Return $true } Else { Return $false } } 'eq' { If ( $WindowsBuild -eq $eq ) { Return $true } Else { Return $false } }
} }
} }
## Function to determine if the system is 64-bit or not
Function Is64bit
{
switch ( $(Get-CimInstance -ClassName Win32_OperatingSystem -Property OSArchitecture | Select-Object -ExpandProperty OSArchitecture) )
{ '64-bit' { Return $true } '32-bit' { Return $false } }
}
## Function to determine if the Powershell process is 64-bit or not
Function Is64bitShell
{ If ( [Environment]::Is64BitProcess ) { Return $true } Else { Return $false } }