Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account

Powershell - how to add routes on multiple servers

Powershell static route route

  • Please log in to reply



    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"| 
    $newProc=([WMICLASS]"\\$_\root\cimv2:win32_Process").Create('c:\windows\system32\cmd.exe /C route -p ADD MASK 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




    Trusted Helper

  • Malware Removal
  • 4,974 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