Author Posts

July 23, 2014 at 6:12 am

Hi all,

I want to install .exe files on remote machines and want to configuration in that.

Example : Want to install software Salt minion on remote machines and after installation want to change config file, manually am doing by opening c:\salt\config\minion in that i want to change master parameter value as APPLE.

may i know how to do in powershell scripting ? Pls help me

Herewith I have attached shellscript file same like that want in powershell pls

July 23, 2014 at 6:23 am

here the shell script content was

#!bin/bash
#
#
#
#

#————————————-
# VARIABLE DECLRATION SESSION
#————————————-
export PATH=$PATH:/tmp/
FILE="/tmp/minion_rhel6.zip"
DIR="/tmp/saltminion_rhel6"

function wait() {
local msg1=$1
local msg2=$2
local msg3=$3
echo -e "33[0m$1 $2 \t\t\t\t\t\t"" \e[38;5;46m$3\e[00m "
sleep 1
}

#———————-
# Pre-checking
#———————-
if [ -d $DIR ];then
wait "CHECKING" "EXISTING PACKAGES" "EXIST"
rm -rf /tmp/saltminion_rhel6
wait "DELETING" "EXISTING PACKAGES" "DONE"
fi
#—————————
# Host name verify
#—————————

SM_NAME=`grep 'salt.rjil.net' /etc/hosts`

if [ -n "$SM_NAME" ];then
wait "SALT-MASTER'S" "HOST ENTRY" "EXIST"
else
wait "SALT-MASTER'S" "HOST ENTRY" "\e[38;5;196mFAIL\e[00m"
cp /etc/hosts /etc/hosts_bkp
echo "100.11.23.58 salt.home.net salt" >>/etc/hosts
wait "SALT-MASTER'S" "HOST ENTRY" "DONE"
fi
#———————–
# Salt Installation
#———————

unzip $FILE -d /tmp/ 2> /dev/null 1> /dev/null
if [ $? -eq 0 ]; then
wait "EXTRACTION OF" "SALT-TAR PKGS" "DONE"
if [ -d $DIR ];then
wait "CREATED" "/tmp/SALT DIRECOTRY" "DONE"
else
wait "CREATED" "/tmp/SALT DIRECOTRY" "\e[38;5;196mFAIL\e[00m"
fi
else
wait "EXTRACTION OF" "SALT-TAR PKGS" "\e[38;5;196mFAIL\e[00m"
fi

#——————–
#
#——————-
cd $DIR
YUM=`yum –nogpgcheck –disablerepo '*' localinstall /tmp/saltminion_rhel6/* -y |tail -n1`
if [ $? -eq 0 ];then
wait "PAKAGES" "INSTALLATION STATUS " "$YUM"
#———————
# Salt master entry
#——————-
HNAME=`hostname`
SALT_MIN=`grep 'master: salt.home.net' /etc/salt/minion`
SALT_ID=`grep "$HNAME" /etc/salt/minion`

if [ -n "$SALT_MIN" ];then
wait "MASTER ENTRY" "IN CONF FILE" "EXIST"
else
wait "MASTER ENTRY" "IN CONF FILE" "\e[38;5;196mFAIL\e[00m"
sed -i 's/master: salt/\nmaster: salt.home.net/g' /etc/salt/minion
wait "MASTER ENTRY" "IN CONF FILE" "DONE"
fi

if [ -n "$SALT_ID" ];then
wait "HOSTNAME ENTRY" "IN CONF FILE" "EXIST"
else
wait "HOSTNAME ENTRY" "IN CONF FILE" "\e[38;5;196mFAIL\e[00m"
sed -i "s/id:/\nid: $HNAME/g" /etc/salt/minion
wait "HOSTNAME ENTRY" "IN CONF FILE" "DONE"
fi

#——————————————
echo -e "\nRESTARTING salt-minion service ######################################### [100%]\n"
/etc/init.d/salt-minion restart
rm -rf "/tmp/saltminion_rhel6" 2> /dev/null 1> /dev/null
echo " "
wait "DELETING" "EXISTING PACKAGES" "DONE"
else
wait "SALT MINION" "PKG. INSTALLATION" "\e[38;5;196mFAIL\e[00m"
fi

July 23, 2014 at 1:53 pm

Hello Pandiyan,

I would use Copy-Item to get the EXE onto the remote machine followed by Invoke-Command to run it with the silent parameters using Start-Process.

http://docs.saltstack.com/en/latest/topics/installation/windows.html#silent-installer-option

Copy-Item:
http://technet.microsoft.com/en-us/library/hh849793.aspx

Invoke-Command
http://technet.microsoft.com/en-us/library/hh849719.aspx

Start-Process:
http://technet.microsoft.com/en-us/library/hh849848.aspx

Example:

Invoke-Command -ComputerName ??? -ScriptBlock { Start-Process -Wait -FilePath C:\???\Salt-Minion-2014.1.7-AMD64-Setup.exe -ArgumentList '/S', '/master=mymaster', '/minion-name=myminion' }

Best,
Daniel

July 23, 2014 at 10:12 pm

Hi Daniel,

Thanks for your reply, and do one more help

1 )When am running this command on host machine, its asking permission to allow program yes or no, after Clicking Yes, its installing ( default windows installing will have this features), how can i automate it

2) I tried to replace the content of file ( find "#master = salt" replace "master = mysalt" )

(get-content c:\salt\conf\minion) | Foreach-object {$_ -replace '\[#master = salt]',master = mysalt'} | Out-file minion

after running this command no changes taken place.

Could you help me on this ?

July 25, 2014 at 12:04 am

The installer will modify the configuration file for you. You only need to run the installer on the remote machines with the correct master and minion name.

Regarding the Yes and No dialog, you probably ran the installer without Administrator rights on your local machine. The dialog should not appear if you run the command against a remote machine.

Best,
Daniel

July 28, 2014 at 1:48 pm

Can someone confirm that when you use invoke-command to execute a command on a remote machine it does so under the credentials of the login that executed the command ?