Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

execute powerhsell script on multipl vm

Posted on 2016-10-11
6
Medium Priority
?
77 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 85

Accepted Solution

by:
oBdA earned 2000 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 85

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 85

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

618 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