Solved

powershell script on Vcenter VLAN

Posted on 2016-10-12
1
37 Views
Last Modified: 2016-10-13
Scenario: run my powerhell script on all virtual machines connected to VLAN 10.X.X.15, in Vcenter?
The script I want to run is the following:
(Get-Content C:/sample.txt -TotalCount 1) | Set-Content C:/sample.txt

What would be my best option?

Best Regards
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
1 Comment
 
LVL 81

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 41841152
many many possible solutions

you need to make up a list of the machines you wish to query. Using this list you can use Powershell Remoting or as an administrator connect to the c$ administrative share..

one possible solution

$computers = get-adcomputer -Filter *
foreach($computer in $computers){
write-output $computer.Name


    if((Test-Connection $computer.name -Count 1 -ErrorAction SilentlyContinue)){
        $pathtotest = "\\" + $computer.name + "\c$\sample.txt"
        if ((Test-Path $pathtotest) -eq $true){
        get-content $pathtotest -TotalCount 1 | set-content $pathtotest
            }
            else {
            write-output ($pathtotest + ' :Not found')
            }
        }
}

Open in new window

1

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

If we need to check who deleted a Virtual Machine from our vCenter. Looking this task in logs can be painful and spend lot of time, so the best way to check this is in the vCenter DB. Just connect to vCenter DB(default DB should be VCDB and using…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Teach the user how to use create log bundles for vCenter Server or ESXi hosts Open vSphere Web Client: Generate vCenter Server and ESXi host log bundle:  Open vCenter Server Appliance Web Management interface and generate log bundle: Open vCenter Se…
This video shows you how easy it is to boot from ISO images for virtual machines with the ISO images stored on a local datastore on the ESXi host.

752 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