My requirement, i have a PowerShell script need to deploy it through ansible. the script needed to open the powershell as administrator. but during the installation the installer tried to start subcommand to install service from C:\Program files\quest\service.exe --install, it is getting failed here because this is going to non admin powershell. the same script if i run manully in the server it is getting through the installation is successfull. the user which ansible login to the machine is already part of administrator and it is domain user
my script is
Function Check-RunAsAdministrator()
{
#Get current user context
$CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
#Check user is running the script is member of Administrator Group
if($CurrentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator))
{
Write-host “Script is running with Administrator privileges!”
}
else
{
#Create a new Elevated process to Start PowerShell
$ElevatedProcess = New-Object System.Diagnostics.ProcessStartInfo “PowerShell”;
# Specify the current script path and name as a parameter
$ElevatedProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'"
#Set the Process to elevated
$ElevatedProcess.Verb = "runas"
#Start the new elevated process
[System.Diagnostics.Process]::Start($ElevatedProcess)
#Exit from the current, unelevated, process
Exit
}
}
#Check Script is running with Elevated Privileges
Check-RunAsAdministrator
#Place your script here.
Import-Module "C:\Program Files\Quest\ChangeAuditor\Client\ChangeAuditor.PowerShell.dll
$password = convertTo-SecureString “xxxxxx” -AsPlainText -Force
$dbcredential = New-Object System.Management.Automation.PSCredential(“xxxx@domain.com”, $password)
Install-CACoordinator -MsiPath “D:\Quest.msi” -DatabaseServer “sqlmi” -AzureADAuthDatabaseCredential $dbcredential -Databasename “ChangeAuditor” -LogPath “D:\install.log”