PowerShell: Stop Service, Rename dir, copy dir, run the make link command, start the service, close session.. Install MSI to ServerList2

Job ID: 31239525

Budget: $30 – $250 USD

Hello,
This may be %80 done and no issues manually, but need to do to a list of target remote machines from my tools machine:

$credentials = Get-Credential

#Config path of file Servers.csv

$servers_list = "S:\Servers.csv"

# THE S DRIVE "S:\Servers.csv" ABOVE IS ON MY LOCAL TOOLS MACHINE..

#Check the connection to each PC

foreach($serv in (Import-csv $servers_list)) {

$machineName = $serv.server

Write-Host -f Green "///Process for $machineName...."

# SO I CAN SEE THAT CREDS ARE WORKING TO SRVRS ON 3 DOMAINS..

Invoke-Command -Computername $server -scriptblock{

Get-Service -Name WinRM | Set-Service -Status Running

Get-Service -Name signalfx-agent | Set-Service -Status Stopped

# STOP THE SERVICE ON EACH MACHINE IN THE LIST SO THAT I CAN RENAME THE FOLDER THAT IT RUNS FROM BELOW..

Rename-Item -Path "C:\SignalFxAgent" -NewName "C:\SignalFxAgent_v5.1.6" -Force

Copy-Item -Path "S:\SignalFxAgent" -Destination "C:\SignalFxAgent" -Recurse

# COPY A NEW FOLDER ALSO FROM MY TOOLS MACHINE S DRIVE, S:\"SignalFxAgent" TO C:\"SignalFxAgent" (REPLACMENT-UPGRADE)

New-Item -ItemType symboliclink -Name "signalfx" -Path "C:\SignalFxAgent\etc\signalfx\" -Target "C:\ProgramData\SignalFxAgent\"

# THIS IS A WEIRD SYMBOLIC LINK CREATION THAT THE SERVICE GETS FROM ONE DIRECTORY TO LINK TO THE OTHER - IT WORKS..

Get-Service -Name signalfx-agent | Set-Service -Status Running }

# NOW WE START THE SERVICE BACK UP ON EACH MACHINE WITH IT'S NEW DIRECTORY AND WE'RE UPGRADED!

Write-Host "@#@#@ Session Closed"

Write-Host "========================================================================================"

}

# MANUALLY I SUCCESSFULLY DID ALL OF THIS REPRESENTING THE ABOVE:

# 1.Stop Service, 2.Rename DIR, 3.Copy in new replacement same name DIR,
# 4.Cmd line: mklink /D "C:\SignalFxAgent\etc\signalfx" "C:\ProgramData\SignalFxAgent", 5. START the Service..

# That's it - all of that works manually as well so just linking together now.

# I know I'm close to save some work and time for the $50 on these tasks that we talked about.
# So with that and for $50 total, I'd like to install 1 MSI installer package to a 2nd server list:
# INSTALL NEW MSI -- from same Tools machine S drive:
# S:\NewInstaller.MSI To the 2nd list $servers_list = "S:\MSI-Servers.csv"
Related categories: Powershell