I am trying to get an application to install on a remote server using powershell. Here is the script I am using:
$cred = Get-Credential
$s = New-PSSession -ComputerName $ServerName -Credential $cred
Invoke-Command -Session $s -ScriptBlock {Start-Process -FilePath "c:\windows\system32\msiexec.exe" -ArgumentList "/i \\computer\e$\installer.msi /qn" -Wait}
Remove-PSSession -ComputerName $ServerName
If I run the following on the remote computer directly, it executes beautifully:
Start-Process -FilePath "c:\windows\system32\msiexec.exe" -ArgumentList "/i \\computer\e$\installer.msi /qn" -Wait
But when I run it remotely as a part of the Invoke-Command, the PS Session is opened, the script runs, msiexec starts on the remote computer, then the PS Session closes but the application never installs and msiexec never closes.
Any help would be appreciated.
Thanks,
Zach
You'll need to copy the package locally first.
Once you start remoting you can no longer UNC.
The destination can be anywhere on the server/computer.
I use the temp but it's whatever you like.
Also I like to use $env:windir\temp, just in case.
Copy-item "\\servershare\File.msi" -conatiner -recurse `
\\$Computer\c$\windows\temp\
Invoke-Command -Computername $Computer -credential $cred -ScriptBlock {
Start-Process -FilePath `
"c:\windows\system32\msiexec.exe" `
-ArgumentList "/i `
\\computer\e$\installer.msi /qn" -Wait
}
I hope it helps.
Related
I have one WFO.exe file which I want to register .
I am able to run below command on remote desktop using powershell and a specific APPID is generated in Dcom config under component services:
c:\WFO.exe /RegServer
c:\WFO.exe /Service
But when I try to run this command through Packer powershell APPId is not getting created.
I tried multiple commands, but nothing is working
Start-Process -Wait -FilePath c:\WFO.exe -ArgumentList "/RegServer" -passthru
Start-Process -Wait -FilePath c:\WFO.exe -ArgumentList "/Service" -passthru
Invoke-Command -ScriptBlock {
Start-Process -Wait -FilePath "c:\WFO.exe" -ArgumentList "/s /RegServer" -PassThru
}
Invoke-Command -ScriptBlock {
Start-Process -Wait -FilePath "c:\WFO.exe" -ArgumentList "/s /Service" -PassThru
}
Do I need to import anything to work it through Packer Powershell?
wondering if there is a way to make powershell not open UAC prompt and just run through an install script, for example
Get-Url http://dl.google.com/chrome/install/375.126/chrome_installer.exe c:\temp\chrome_installer.exe
Start-Process -FilePath 'c:\temp\chrome_installer.exe' -ArgumentList '/silent', '/install' -Wait
Start-Process -FilePath 'C:\temp\DifferentProgram.exe' -ArgumentList '/argument' -Wait
I have a script where my users get to install programs in on their computers.
the logic is -> copy from network path the installation file to the local hard drive of the computer,
run the installation file with different creds
I want to then delete the file but this code isnt good
copy-item "$path1" -Destination C:\ProgramData\ #copy from network path to local
$progyname = [System.IO.Path]::GetFileName($path1) #holding the programname.exe
Start-Process powershell -Credential $creds -workingdirectory c:\programdata\ -ArgumentList "-Command &{Start-Process $progyname -Verb RunAs}"
Remove-Item -path c:\programdata\$progyname -Force
Problem is the script will delete the item too soon, i actually want to wait for the installation to be completed and then delete the file.
what could work here?
Use the passthru parameter for start-process, save the returned ID to a variable and wait until the process is closed and youre good to delete
You can try this:
copy-item "$path1" -Destination C:\ProgramData\ #copy from network path to local
$progyname = [System.IO.Path]::GetFileName($path1) #holding the programname.exe
Start-Process powershell -Credential $creds -workingdirectory c:\programdata\ -ArgumentList "-Command &{Start-Process $progyname -Verb RunAs}"
$pro = $progynane.basename
If (!(Get-Process $pro -ErrorAction SilentlyContinue)){Remove-Item -path c:\programdata\$progyname -Force}
Or if you like you can -Wait parameter at end of Start-Process as #Lee_Dailey pointed.
Running PS as admin, trying to run an exe from server (or even if i copy this file to my computer and trying to run it locally)
$apps = "\srv\blabla"
Start-Process $apps\mbsetup.exe -Credential $Credentials
Error:
without -credential this would work, i would assume something bad with the user definition but the creds are that of the domain admin.
any idea?
It looks like your app requieres administrative privileges. Add -Verb RunAs to your Start-Process cmdlet to elevate the execution.
But -Verb RunAs will not work in combination with -Credential. This is a workaround:
Start-Process powershell -Credential $Credentials -ArgumentList "-Command &{Start-Process yourApp.exe -Verb RunAs}"
Hello I want my powershell script to be able to copy a file from a mapped drive (Z:) and copy it to the user in the domains "C:/temp/" folder. Currently, my script looks like this.
$Computer = Read-Host -Prompt 'Enter the Computer Name you are accessing'
########## Install Software On PC ##########
New-Item -ItemType directory -Path "\\$Computer\c$\temp\openVPN"
Copy-Item "Z:\(15) IT\VPN\openvpn-install-2.4.8-I602-Win7.exe" "\\$Computer\c$\temp\" -Recurse
Copy-Item "Z:\(15) IT\VPN\office.opvn" "\\$Computer\c$\temp\" -Recurse
Write-Host "Installing openVPN on $Computer"
Invoke-Command -ComputerName $Computer -ScriptBlock {Start-Process "c:\temp\openVPN\openvpn-install-2.4.8-I602-Win7.exe" -ArgumentList "/q" -Wait}
Invoke-Command -ComputerName $Computer -ScriptBlock {Start-Process "c:\temp\openVPN\openvpn-install-2.4.8-I602-Win7.exe" -ArgumentList "/q" -Wait}
However, I receive the error
Copy-Item : Cannot find drive. A drive with the name 'Z' does not exist.
Would appreciate any help!
For some reason, your session is not seeing the Z drive.
Disconnect the Z drive if you can. Then map the drive in the same session using New-PSDrive PowerShell command, before accessing the Z drive.
New-PSDrive –Name "Z" –PSProvider FileSystem –Root "\\servername\path" –Persist
Also, try to run PowerShell in both standard mode and 'Run As Admin' mode.