Solved

execute powerhsell script on multipl vm

Posted on 2016-10-11
6
69 Views
Last Modified: 2016-10-11
I have a powershell script, that run's at user log in on one VM (00000281):
Get-Content C:/sample.txt -TotalCount 1) | Set-Content C:\sample.txt

To execute the script automatically I have created a .cmd file and placed it in the following folder:
C:\Users\vs_domadmin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

The above VM(00000281) resides in my infra VM's cluster which contains four other Vm's (infra servers). I have a total of four servers, which I would like that script to run as well.
00000281, 00000282, 00000283, 00000284

My script is runniing for the moment only on the 00000281. Here is the trick:
I need that script from 00000281 to execute also on the rest of the infra servers 00000282, 00000283, 00000284, knowing that the script will be stored only on my first infra server 000002821. I believe that giving the script some conditions and outlining the path of the other 3vms in VM (00000281) should do the work correct? As am very new to powershell can someone please help?
0
Comment
Question by:Maniman man
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41838258
Just use the UNC for the remote machines:
$File = "C:\sample.txt"
Get-Content $File -TotalCount 1 | Set-Content $File
"00000282", "00000283", "00000284" | % {
	$FileUnc = "\\$($_)\$($File.Replace(':', '$'))"
	Get-Content $FileUnc -TotalCount 1 | Set-Content $FileUnc
}

Open in new window

1
 

Author Comment

by:Maniman man
ID: 41838524
I have tried to do so, but as Im new to powershell am not sure how to use the above. Could you please verify and advise?
$File = "C:\sample.txt"

Get-Content $File -TotalCount 1 | Set-Content $File
"00000282", "00000283", "00000284" | %
{
      $FileUnc = "\\$($_)\C$\C:\cldscripts\macs_reference.txtC$\($File.Replace(':', '$'))"
      Get-Content $FileUnc -TotalCount 1 | Set-Content $FileUnc
}

Is the above syntax correct?
0
 
LVL 84

Expert Comment

by:oBdA
ID: 41838538
No.
Assuming that the file you want to process has the same name and location on all four servers, all you need to do is change the path in line 1, nothing else.
1
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:Maniman man
ID: 41838552
ok so assuming file I want to process is C:\sample.txt, which is the same location for all four servers,the syntax should look like below correct?

$File = "C:\sample.txt"

Get-Content $File -TotalCount 1 | Set-Content $File
"00000282", "00000283", "00000284" | %
{
      $FileUnc = "\\$($_)\C$\C:\sample.txtC$\($File.Replace(':', '$'))"
      Get-Content $FileUnc -TotalCount 1 | Set-Content $FileUnc
}

Is the above syntax correct?
0
 
LVL 84

Expert Comment

by:oBdA
ID: 41838564
Still no.
As I said: change the path in line 1, nothing else (and if the file is actually C:\sample.txt, then there's nothing at all to change).
1
 

Author Closing Comment

by:Maniman man
ID: 41838625
It worked, thanks
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
Advanced tutorial on how to run the esxtop command to capture a batch file in csv format in order to export the file and use it for performance analysis. He demonstrates how to download the file using a vSphere web client (or vSphere client) and exp…
This Micro Tutorial walks you through using a remote console to access a server and install ESXi 5.1. This example is showing remote access and installation using a Dell server. The hypervisor is the very first component of your virtual infrastructu…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question