fix Install-ManagementAgent script to include correct installshield switches
added Create-LocalAdmin.ps1 with base functionality updated Tools.ps1
This commit is contained in:
@@ -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
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -205,4 +205,15 @@ switch ($PSCmdlet.ParameterSetName)
|
|||||||
'le' { If ( $WindowsBuild -le $le ) { Return $true } Else { Return $false } }
|
'le' { If ( $WindowsBuild -le $le ) { Return $true } Else { Return $false } }
|
||||||
'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 } }
|
||||||
|
|||||||
Reference in New Issue
Block a user