Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save virtualhobbit/df7c820655b6931c177a9b5e97586d0a to your computer and use it in GitHub Desktop.
Save virtualhobbit/df7c820655b6931c177a9b5e97586d0a to your computer and use it in GitHub Desktop.
# Format the username
if ($userName -ne $null) {
$user = $userName + "@" + $userDomain
} else {
$user = $userName
};
# Add the user to the Gugent group
$group = "Gugent"
Add-LocalGroupMember -Group $group -Member $user
# Set vRA Software Agent Bootstrap to logon using local account
$serviceName = 'vRASoftwareAgentBootstrap'
$computerName = 'localhost'
$filter = 'Name=' + "'" + $serviceName + "'" + ''
$service = Get-WMIObject -ComputerName $computerName -namespace "root\cimv2" -class Win32_Service -Filter $filter
Write-Output "Changing service $serviceName to run as account $userName"
$result = $service.Change($null,$null,$null,$null,$null,$null,$user,$userPass,$null,$null,$null)
if ($result.ReturnValue -eq '0') {
Write-Output "Service $serviceName logon account changed"
} else {
Write-Output "Error: $serviceName logon account not changed"
};
# After hours of working on this, I know the service won't stop gracefully. Kill it with fire...
Write-Output "Stopping service $serviceName"
$servicePID = (Get-WMIObject -class Win32_Service | Where-Object Name -eq $serviceName).processID
Stop-Process $servicePID -Force
# Start the service
Write-Output "Starting service $serviceName"
try
{
Start-Service -Name $serviceName -ErrorAction Stop
Write-Output "Service $serviceName started"
}
catch
{
Write-Output "Error: $serviceName failed to start"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment