Solved

execute powerhsell script on multipl vm

Posted on 2016-10-11
6
39 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
  • 3
  • 3
6 Comments
 
LVL 83

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 83

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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 83

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
This video shows you how to use a vSphere client to connect to your ESX host as the root user. Demonstrates the basic connection of bypassing certification set up. Demonstrates how to access the traditional view to begin managing your virtual mac…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now