IMHO: For me working with Powershell is always about automation and running stuff in the background. I rarely provide tools for others containing actions running long enough to be worth having some kind of entertaining while you’re waiting for something … like a progressbar. If something takes that long I wouldn’t try to make that more enjoyable. I would try to make it faster - to make it less anoying. … the download of the mariadb installer takes about 10 to 15 seconds for me. I would suggest not to spend that much effort to get a nice progressbar and make it pretty. I would suggest to spend the effort to make it fast, reliable and fault tolerant.
I’ve tried many time , but I can’t run a script as admin from another script
function set-MariaDbservice {
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Host "MariaDB service needs to be run As Admin" -ForegroundColor Red
Who is supposed to run this script? Installing a database should be the task for administrators anyway. If the user has sufficient rights (administrative rights) it should be enough to use the statement #Requires -RunAsAdministrator at the top of the script. This would prevent to run the script without necessary rights.
Is this a regularly recurring task in your environment?
So you might do a little step back, take a little time and start with learning the very basics of Powershell from scratch. Otherwise it will be hard or sometimes nearly impossible for you to understand the help you get in forums like this or in StackOverflow.
One easy way to get started is to watch the free video course with Jeffrey Snover on Channel 9: “Microsoft Channel 9 - Getting Started with Microsoft PowerShell 3.0”
A complex technology like Powershell cannot be learned properly by asking arbitrary questions in forums or by copying code snippets from the internt.
I’m not a database guy so I don’t know about the correct options for MariaDB but if you start your Powershell console as admin the following code installs MariaDB with the given options:
Of course you can change or add or remove options to make it suitable for your needs.
Regardless of that: Please - before you ask a question in a forum spend a little effort to solve the problem yourself. Most of the time you’re not the first one with a given task and others probably solved it already.
The technique I use here to make the code easier to read is called Spaltting. You can learn more about when you run
I saw many syntax errors and error messages didn’t help always
Below is the code (not final)
my previous errors: Every step took me some time.
‘-Credential’ is different from ‘RunAs’
<sup>`$c = Get-Credential`</sup>
<sup>`Start-Process cmd.exe -arg “/k C:\eclipse2019-12\Workspace\db\startMaria.bat” -Credential ($c)`</sup>
if your run script.ps1 renember to set -ExecutionPolicy Bypass
You can insert it in the batch file or within the script
When you start service you need Admin rights, ok but I dont want start the first script as Admin
so How Can I run an elevated script from a non-elevated ? `powershell.exe "Start-Process powershell C:\eclipse2019-12\Workspace\db\startMaria.bat -verb runAs"`
I dont want another windows console `powershell.exe "Start-Process powershell -WindowStyle Hidden C:\eclipse2019-12\Workspace\db\startMaria.bat -verb runAs"`
I dont want to use batch file. Run only the ps1 file `Start-Process powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"C:\eclipse2019-12\Workspace\db\Start_MariaDB.ps1`"" -Verb RunAs `
I want to replace string with variable `$script = "C:\eclipse2019-12\Workspace\db\Start_MariaDB.ps1"` `Start-Process powershell.exe “-NoProfile -ExecutionPolicy Bypass -File $script” -Verb RunAs` <------------- works!
7 ) How Do I put inline ‘-WorkingDirectory’ ?
It still doesn’t work
I think you are overcomplicating the installation process. Assumed you started your Powershell console elevated the following snippet should be enough to install MariaDB server