From 95abcf57c4b0a0e39356f968da7dff433620cec1 Mon Sep 17 00:00:00 2001 From: dyoder Date: Fri, 25 Sep 2020 13:13:03 -0400 Subject: [PATCH] fix Install-ManagementAgent script to include correct installshield switches added Create-LocalAdmin.ps1 with base functionality updated Tools.ps1 --- Create-LocalAdmin.ps1 | 42 +++++++++++++++++++++++++++++++++++++ Install-ManagementAgent.ps1 | 2 +- Tools.ps1 | 13 +++++++++++- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/Create-LocalAdmin.ps1 b/Create-LocalAdmin.ps1 index e69de29..a583050 100644 --- a/Create-LocalAdmin.ps1 +++ b/Create-LocalAdmin.ps1 @@ -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 \ No newline at end of file diff --git a/Install-ManagementAgent.ps1 b/Install-ManagementAgent.ps1 index 42bca6a..a3ff09f 100644 --- a/Install-ManagementAgent.ps1 +++ b/Install-ManagementAgent.ps1 @@ -58,7 +58,7 @@ If ( $CUSTOMER_ID -and $TOKEN ) ## Install the 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 } ## Remove the agent installer diff --git a/Tools.ps1 b/Tools.ps1 index 55f10ec..96dce06 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -205,4 +205,15 @@ switch ($PSCmdlet.ParameterSetName) 'le' { If ( $WindowsBuild -le $le ) { Return $true } Else { Return $false } } 'eq' { If ( $WindowsBuild -eq $eq ) { Return $true } Else { Return $false } } } -} \ No newline at end of file +} + +## 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 } }