Install application on remote server using local installer - powershell

I have an installation file (*.msi) which installs a service. I would like to install this service on a remote server.
Doing that via Remote Desktop is not a problem, but I cannot find a solution for doing that automatically using a batch file or a PowerShell command that would install application remotely using the local file.
What is the problem:
I have a Bamboo CI server that results in the installation file. I'd like to install the application on a remote server using the script, without copying the installation file (similar way to deploying application using the Ms Web Deploy).
Is it possible to do this in that way?
So far I have tried installutil.exe (works locally, but I cannot configure it to install it remotely), ServiceConsole, but it somehow doesn't install correctly application using create command and I can't overwrite the application.

i do that before
first download msi or exe command with invoke-webrequest like
invoke-webrequest http://mysiteapp -outfile c:\myapp.msi
then
you can install app with msiexec or some app can install like this
myapp.msi /quite
if you have telnet from server you can make script and then run...
if you have not access telnet you should use invoke-command or psexec
this link can help you

The executable to use when installing .msi files is msiexec.exe; you can call that remotely using PowerShell's Invoke-Command cmdlet, and pass it the remote path to the .msi file as a parameter (look up the msiexec.exe syntax for details).
The trick will be getting access to the .msi file on the local server from the remote PowerShell session. You will almost certainly need to create the session using CredSSP authentication, so that the remote PowerShell session created by Invoke-Command will be able to make a connection back to your local server and access the .msi file.
I hope this sets you on the right path.

Related

Triggering a remote powershell script to run independently

I've created a script which calls 'dfsutil', and is available for all the members in my team. Some members don't have RSAT (dfsutil) installed locally, so I'd like to 'trigger' a .ps1 script independently of the source PC (PC1) to be run on a server (Server1) which has 'dfsutil' installed.
It's easy enough to trigger a remote PowerShell script from the source 'PC1' by dot-sourcing it from 'myscript.ps1':
. \\Server1\scripts\dfsscript.ps1
As we already know, the above will fail as PowerShell is looking for 'dfsutil' locally on PC1, rather than on the server 'Server1'.
'dfsscript.ps1' has been written so it can be run independently, without need to return the values to PC1.
I can't seem to find any documentation which shows how to initialise a remote script which only uses the values and conditions of the OS it was triggered on.
Any thoughts?
Dot-sourcing is about the scope of a PowerShell session, but doesn't include the computing environment, so what you are doing won't get the script on Server1 to run from Server2, but still act like it is on Server1 with access to all of Server1's installed apps, etc.
What you need to do is use PowerShell remoting to actually run the script on the remote server (i.e. trigger from Server2, but execute on Server1). For example:
Invoke-Command -ComputerName Server1 -FilePath <path>\script.ps1

Powershell script to copy publish files from build machine to posting server

I am designing TFS build definition to build solution on a build machine and publish files to posting server. I need to copy those publish files directly from build machine to posting server (which is a shared drive that i need to login using credentials).
Till now, we are posting the build results to a shared drive. I have used powershell commands to do this. From there, we are manually updating the files in posting server. Now i am trying to post directly to posting server rather than involving the manual process.
I need a powershell script to
Login to posting server
Delete the specific files in the posting server
Copy publish files from build machine to posting server
Logoff from posting server after successful copy
I have got the script to everything except including user credentials to login to the destinationpath. I am trying to find some arguments to include login username and password for this destination path, but could not found anything appropriate.
Can this be done using MS Build Arguments instead of script?
Copy a file to a remote computer:
$Session = New-PSSession -ComputerName "Server01" -Credential "Contoso\PattiFul"
Copy-Item "D:\Folder001\test.log" -Destination "C:\Folder001_Copy\" -ToSession $Session
Once you type a user name, you will be prompted for a password.

Load Azure PowerShell Cmdlets onto Remote VM

I am using PowerShell to automate the creation of a virtual machine in Azure, then using Remote PowerShell to run commands on that machine. I can run any PowerShell command that ships with Windows perfectly well, but when I try to run something like:
Set-AzureSubscription or Get-AzureStorageBlobContent
I get the following message:
The term 'Set-AzureSubscription' is not recognized as the name of a cmdlet, function, script file, or operable program.
Of course, because the Azure module is not preloaded on the VM in Azure. Is it possible to copy the Azure Module up to the VM using PowerShell? Or any other way to go about this assuming everything must be automated with PowerShell (so I can't log into the VM to run the Azure PowerShell installer or copy and paste over a remote desktop session)?
Did use the Azure Powershell? If not you can install it here:
http://azure.microsoft.com/en-gb/documentation/articles/install-configure-powershell/
This is because you don't have Azure module installed
Try this to check:
Get-AzureModule Azure
You shoud get the module here:
http://azure.microsoft.com/en-us/downloads/#cmd-line-Tools

Powershell, remote script access denied to network resources

I am trying to execute powershell script remotely using invoke-command. The script relies on a configuration file which is available over the local network. The script is called in a following way:
Invoke-Command -ComputerName 192.168.137.181 -FilePath c:\scripts\script.ps1 -ArgumentList \\192.168.137.1\share\config.xml
The configuration as you can see is an xml file and it's loaded using:
$xml = New-Object XML
$xml.Load(args[0])
When the script is called locally on the machine then it runs witout any problems and reads the configuration file. However when I run it from different machine using invoke command I get
"Access to the path '\\192.168.137.1\share\config.xml' is denied"
exception, which is thrown when executing Load method.
The file is accessible to everyone with read and write permissions.
Both, machine on which the scrip should be run (.181) and the machine on which it is run physically have the same credentials, thus I do not pass them in invoke-command cmdlet.
The share machine (.1) has different credential, but this was never an issue when calling the script locally from .181.
Can you please point me in the right direction? I stuck on this step and can't find solution by myself. I tried downloading the xml string using WebClient#DownloadString method and passing credentials for the share machine but it did not help.
Thanks in advance
It is probably a double hop issue. You have to use CredSSP to delegate your credentials to the remote computer.
Try the solution mentioned here: http://blogs.msdn.com/b/clustering/archive/2009/06/25/9803001.aspx

How should I run a Powershell script on a remote computer?

I need to know if it is possible to run powershell remotely in the following scenario:
I have a Windows XP box WITHOUT Powershell installed. From this box, I would like to run a PS script located somewhere like: \\mypc\C$\Scripts\information.ps1.
The script should be run against the machine where it resides. In this case, the “mypc” machine would be running the script and returning the result to the XP machine.
What makes this difficult is the fact that I cannot install Powershell or any third party apps on the Windows XP machine.
It’s a long shot but would this be doable?
Thanks!
While you can't actually run the script on the local machine without PS installed there, depending on what you want to actually accomplish you may be able to run it locally and simply access the remote resources. Most of a machine's resources are typically available remotely (File System, Registry, WMI, etc.) depending on the security on the machine.
EDIT: Now that my complete misunderstanding of the issue is cleared up, my answer would be: No, you do not need to have Powershell installed on a local machine to run a script on a remote machine that does have Powershell installed. Just use PSExec to kick off the Powershell process on the remote machine. I realize that the OP cannot install 3rd party apps, but there is absolutely no install associated with PSExec, it is a completely stand alone exe.
It has been a while since I had to do this so I did a quick check. This at the command line worked for me:
psexec \\REMOTEMACHINE "C:\Windows\system32\WindowsPowershell\v1.0\powershell.exe" -File C:\temp\test.ps1 -NoProfile -NonInteractive
You need to have Powershell installed. This isn't possible :(. Sorry.
Using Psexec is the only way I can think of too. However, if you are using PSexec.exe using alternate credentials, the credentials are passed over the network in plaintext. Something to be wary about if your network is visible to other people.