Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Powershell - how to add routes on multiple servers

Powershell static route route

  • Please log in to reply

#1
YoinkZ

YoinkZ

    New Member

  • Member
  • Pip
  • 1 posts

Hi Guys,

 

I'm new in here, so I hope I've placed the question under the right section - otherwise let me know where to repost it.

 

My problem is that I'm trying to make a powershell script I can run from a Domain Controller and then push out a Static Route to all our servers that are placed in an OU in our AD.

Can someone spot what I'm doing wrong here, in order to make it work?

 

Import-module activedirectory
$=get-adcomputer -filter * -searchbase "OU=ITComputerObjects,OU=TestOU,DC=XXXXX,DC=tc"| 
ForEach-Object{
    $newProc=([WMICLASS]"\\$_\root\cimv2:win32_Process").Create('c:\windows\system32\cmd.exe /C route -p ADD 10.101.0.0 MASK 255.255.0.0 172.18.0.2 metric 2')
 
    if($newproc.ReturnValue -ne 0){Write-Host "Creating process on $($_) failed"}
    }
 
The whole idea is that the script should look into the OU i've specified, then for each object inside the OU it should run the newProc and open CMD and then like a normal command put in the details for the above route and then move on to the next object in the OU - and of course at every object let me know if it fails.
 
Thanks guys,

Edited by YoinkZ, 19 January 2016 - 03:51 AM.

  • 0

Advertisements


#2
SleepyDude

SleepyDude

    Trusted Helper

  • Malware Removal
  • 4,374 posts

Hi :welcome:

 

To do a simple task like that I wouldn't use WMI, check the following thread at stackoverflow

 

Using invoke-command a Powershell native command seems more appropriate...

 

Did you get any error running your script? if not did you check if the command worked on the remote machine?


  • 0






Similar Topics


Also tagged with one or more of these keywords: Powershell, static route, route

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP