Hy,
I would install PostGreSQL 9.1 on a Windows Server 2012.
I want to used a PowerShell script.
With my JDK executables file, I use Start-Process "Myfile" -ArgumentList "/s" -Wait
But the argument \s don't work with my PostGre executables file.
Have you an idea ?
You can use Install-Postgres Powershell module, it's on TechNet Gallery.
The Install-PostgreSQL PowerShell module does the following:
creates a local windows user that PostgreSQL will use
downloads the PostgreSQL installer provided by EnterpriseDB
installs Postgres unattended using the supplied parameters
sets postgres windows user as owner of Postgres files and folders
sets Postgres windows service to run under postgres local user
creates pgpass.conf file in AppData
copies configuration files to data directory
opens the supplied port that PostgreSQL will use in the Windows
Firewall
Usage
Import-Module Install-Postgres
Install-Postgres -User "postgres" -Password "ChangeMe!"
I have used this command : Start-Process $installFile -ArgumentList "--unattendedmodeui minimal --mode unattended --prefix $dest --datadir $dest\data --servicepassword $pwd" -Wait
Thanks for your help ! :)
Related
I am facing a difficulty on installing RSAT to remote windows 10 workstations via gpo. My main goal is to use Get-ADuser command as a necessity to gain information from my Windows domain.
I created a PowerShell script using the following command:
Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability –Online
Yet when I run it, a message appears asking for elevated privileges.
So I tried to add credentials in order to automate the installation and changed the script to :
$Username = 'domain\domain_adm'
$Password = '*******'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
Start-Process -FilePath powershell.exe -ArgumentList{Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability –Online} -credential $Cred
And from a normal PowerShell window, it works. But, it doesn't when I am trying to use it from gpo.
Could you please assist me?
The goal is to install via GPO Get-ADuser (maybe RSAT) to domain workstations with OS Windows 10
For a small number of machines Powershell is not a bad option. If you have access to GPOs then you should use then. RSAT is "Windows feature". You can use WSUS. https://4sysops.com/archives/install-rsat-1809-and-other-optional-features-in-wsus-environments/ You could also use the software that you use to install software on the machine on the network . Many of software distribution packages run as root when it installs software. In this case just give that team the line below.
Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability –Online
Why are you putting credentials in clear text in a script file? That
is just bad practice and should not be done.
Installing software is an Admin level thing, local, GPO, or
otherwise, because it's a system-wide change.
Lastly, this is not a PowerShell code/programming issue and not something PowerShell can fix relative to how you are trying to do this. It's specifically how do I use GPO to enable a Windows feature or install software, using PowerShell?
So, could be considered off-topic for Stackoverflow and more a question for SuperUser or StackExchange.
All that being said, you can still use PowerShell to do this, but doing so by using PowerShell to set a scheduled task to the targets and set that to the admin creds at run once at login.
You can write a separate script to create the scheduled task.
You can use the below script for the RSAT install effort via the task.
Use PowerShell to Create Scheduled Tasks
New-ScheduledTask
Very similar to this approach with updating PowerShell help:
PowerShell: Update-Help via Scheduled Task in Group Policy Preferences
As far as what js2010 has stated. That was true for earlier versions of Windows 10. The current state of things is as noted below.
Install RSAT for Windows 10 1809 and 1903 and 1909 automated
RSAT (Remote Server Administration Tools) in Windows 10 v1809 and
v1903 are no longer a downloadable add-on to Windows. Instead, its
included as a set of "Features on Demand" directly in Windows.
Download: Install-RSATv1809v1903v1909.ps1
Long term Scheduled Task management can be accomplished via GPO as well, as noted here:
Managing Scheduled Tasks from Group Policy
You can download RSAT as an msu file: https://www.microsoft.com/en-us/download/details.aspx?id=45520
EDIT: Ok, as for 1809 and above, my first thoughts are a gpo startup script, or using invoke-command.
I am trying to run a .bat script that uninstall 32/64 bit agents and re-install 64-bit agents on almost 100 window servers.
Can you please guide me how this can be done?
I already tried running for one server to test
psexec \\<windows server> -u <username> -p <password> <command>
But fails with error
COULD NOT START PSEXESVC service on <windows server>
Do we need such service on all machines? Please suggest any other way?
PSEXEC is not a standard windows feature /service.
If you wish to use PS Exec you will need to install it on all of the relevant systems first.
Otherwise, your options are:
CMD:
A) Does the "Agent" Installer you are using allow you to install / uninstall to a given server in it's command line syntax?
If so utilize that.
B) Put the Installer in central location (the Active Directory Netlogon Folder is great for this) along with a CMD script to run the uninstall and install processes.
Then Use SCHTasks to connect to each server and create a Scheduled task that runs using an administrative Username and password for that server, and set it to run with the highest privileges, set the action to be the path to the CMD script in netlogon that you have previously tested and nwo is working, set the task to run 1 minute in the future, or on demand (If on demand you then run schtasks again to execute the task).
Powershell:
Work on getting a working CMD Script to run and use Invoke Command to run that command script on the remote systems. As in Option B from CMD options you can keep the CMD script and Agent installer in the netlogon folder.
I'm trying to install SQL Express on Windows 2012R2 server remotely either using "windows_package/powershell_script" chef resources. I tried executing the script I have after remoting into the machine, it installs fine.
But, when I try to execute it remotely using Chef/Powershell, it's neither installing the software nor giving out an error. Is this because of configuration issues?
Currently when I attempt to use the below resources, nothing is installing:
1. Windows_package:
windows_package 'Install SQL Express' do
source 'C:\\Folder\\SQLEXPR_x64_ENU.exe'
action :install
options '/QUIET /SAPWD="C0mp!ex" /ConfigurationFile="C:\\Folder\\sql_express.ini" /TCPENABLED="1" /SECURITYMODE="SQL"'
end
2. powershell_script:
powershell_script 'Install SQL Express' do
code <<-EOH
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Unrestricted -Force
C:\\Folder\\sql_express.ps1
EOH
end
And the Powershell script that I used is:
$app = 'C:\\Folder\\SQLEXPR_x64_ENU.exe'
$myarg = '/QUIET /SAPWD="C0mp!ex" /ConfigurationFile="C:\\Folder\\sql_express.ini" /TCPENABLED="1" /SECURITYMODE="SQL"'
Start-Process $app -ArgumentList $myarg
Start-Sleep 300
The Powershell script when ran on the machine, it works fine. Why is the script working fine when executed on the machine and not remotely?
Please let me know if I need to make any changes to the script or resources to make it work.
Thanks in advance.
Currently i am working on taskpads for delegating some permissions to remote admins.I have following questions;
-> For Importing active directory module in powershell , shopuld it be locally installed or can it be imported remotely from a windows 2008 R2 DC?
-> For taskpads to work on remote workstations, should the administrative tools be installed on all the remote machines or is there a centralized way of maintaining them?
Please do let me know if anymore clarifications/questions regarding my efforts.
You can import remote module in this way (remoting must be enabled on remote server):
Create a Powershell remote session to a server with the activedirectory module installed.
$Session = New-PSsession -Computername Server1
Use the newly created remote Powershell session to import the module to that session
Invoke-Command -Command {Import-Module ActiveDirectory} -Session $Session
Use that session with the modules to add the available commandlets from the activedirectory module to your local Powershell session adding a name prefix.
Import-PSSession -Session $Session -Module ActiveDirectory -Prefix RM
The code above enables the use of Active Directory commandlets on a computer that doesn’t have this module installed.
Use AD commandlets in the Powershell command shell with modified names based on the -Prefix set above:
Get-RMAdUser instead of the standard Get-ADUser
Get-RMAdComputer instead of the standard Get-ADComputer
You can avoid the -Prefix RM but it's handy for remember that are imported from remote.
For taskpad I'm pretty sure that must be present on each client installing RSAT with the ADUC mmc snap-in.
Ive got a java app which needs to execute a driver installer exe file. On Linux we type "gksudo myCommand". Is there a way to elevate permissions from Windows command line?
You may run every application in windows with a different user e.g. Administrator. But the user who executes this command needs to have the credentials to do so.
Edit.:
In advance you can lookup the User Account Control (UAC) which is available in Windows 7 and Vista if it is possibly an alternative for you.
I decided to deploy an executable binary onto the system which calls the jar. This way the user can right click and run as administrator... That didn't work... SO I kept looking... Check this out..
Elevate.exe.. It's basically like Windows GKSudo!!!!
http://www.robotronic.de/elevate.html
So... I packaged the 32bit exe into my program and deploy it, then run it as necessary.
You can use runas command like runas /user:Administrator myCommand (it requires the users to type password).
You can also use Start-Process cmdlet like Start-Process -Verb runas myCommand in PowerShell (it requires the users to click the UAC dialog).
see: http://satob.hatenablog.com/entry/2017/06/17/013217