How do Install software to a remote computer using chocolatey? - powershell

I have installed chocolatey on my local machine and I want to, to install software remotely using powershell, I would greatley appreciate it If I can receive any help.

invoke-command -ComputerName $remotemachine -Credential (Get-Credential) -ScriptBlock {install choco same way as local}
invoke-command -ComputerName $remotemachine -Credential (Get-Credential) -ScriptBlock {choco install package xyz}
or start a session to the remote client via New-PSSession?

Related

Remote connection always to Powershell 5 - how to connect to Powershell 7?

I try to remotely connect to multiple computers where both versions of Powershell installed: 5.1 and 7.3. Everything goes fine, and I am connected, but always to old Powershell version 5.1.
What I should do to connect to newer Powershell 7.3 ?
This is the connection command:
$sess = New-PSSession -ComputerName server01 `
-SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck) `
-Credential $cred
Enter-PSSession -Session $sess
P.S. I set Enable-PSRemoting on both versions and I actually trying to connect from Powershell 7.3
You can change the default session configurations by using the $PSSessionConfigurationName preference variable:
$PSSessionConfigurationName = 'PowerShell.7';
$sess = New-PSSession -ComputerName server01
-SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck)
-Credential $cred;
Enter-PSSession -Session $sess;
You can find more details about Session Configurations in the docs.

Powershell script guidance

I am looking for powershell code for installing software packages in remote machines which are in ADS domain.While installing I have to pass my admin credentials. How can I do this?
Guidance required
You can store your password to be used on a remote computer using the Get-Credential command like this:
`$Credential = Get-Credential
You'll see a prompt like this appear:
I would recommend storing the applications you need to install in a central place, that all of your remote devices can reach. I'll assume you've stored them in the UNC Path: \\FileServer\Application
Let's say you wanted to install 7Zip and had it present in that path:
$Credential = Get-Credential
$Computers = 'RemotePC1', 'RemotePC2'
Invoke-Command -ComputerName $Computers -Credential $Credential `
-ScriptBlock {& \\FileServer\Application\7Zip.msi} -ArgumentList '/q INSTALLDIR="C:\Program Files\7-Zip"'

Running a remote cmd command in PowerShell

I uploaded some files to a remote host with PowerShell, by FTP. On this host runs Windows 7 Embedded.
It turns out there is EWF (Enhanced Write Filter). So after a restart the uploaded files were gone. For saving the changes it needs commit them in cmd (at the remote host) by: ewfmgr d:-commit How can I include this command in my PowerShell code?
The code:
Enable-PSRemoting -Force
Set-Item wsman:\localhost\client\trustedhosts -Value * -Force
Restart-Service WinRm
Test-WSMan $line
Invoke-Command -ComputerName $line -scriptblock {cmd.exe /c "ewfmgr d: -commit"} -credential $FTPCredential
When I run Enable-PSRemoting -Force manually on the remote computer, it works, but it is uncomfortable and take lots of time. Is there another way to do this once for many hosts simultaneously?
Example-Code:
$session = New-PSSession -ComputerName yourRemoteComputer
Invoke-Command -Session $session -Scriptblock {ewfmgr d: -commit}
Remove-PSSession -Session $session
You have to enable Powershell Remoting on your host to invoke a command like this (https://technet.microsoft.com/en-us/library/ff700227.aspx)
If you need to transmit Credentials to your remote host, you can add the -Credential-Parameter to New-PSSession. This article describes how to add valid Credentials to your script (https://technet.microsoft.com/en-us/library/ff700227.aspx)
Greetings, Ronny

"Get-Service –ComputerName myserver" not working on one of my Virtual Machine in Powershell

I m trying to run powershell script from my machine to get the Services status from a remote machine.
The command I am using in my script is given below
"Get-Service –ComputerName myserver".
My remote machine is a virtual Machine.
I have solved this problem.
However, I don't know why this command not working directly from source to Remote server but I found an alternative. Use given function on source machine and pass server name as param value and it will return all services with their status.
function GetAllservices {
param(
$ComputerName
)
$sess = New-PSSession -ComputerName $ComputerName
Invoke-Command -Session $sess -ScriptBlock {get-service}
Remove-PSSession -Session $sess}

Powershell remote install/app run

I am going to try and install software remotely onto a server and first i am trying to play around with the invoke-command cmdlet in powerhsell. Below is what I have so far
cls
Exit-PSSession
New-PSSession -ComputerName vm912test
Enter-PSSession -ComputerName vm912test -Credential sceris\pmanca
Invoke-Command -Computername vm912test -ScriptBlock {Start-Process "calc.exe" -wait}
Get-PSSession
However when i run this i see no running tasks in task manager. Does anyone know what i am missing? Once i can get this to work i will expand onto trying to remotely install some software first. I have no issues on communicating with the server and i have remote access/admin access on the box.
I updated with some more code but still receiving the same result that nothing is happening.