Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Create a subnet in AD

Reply
 
Old 09-14-2007   #1 (permalink)
BZP


 
 

Create a subnet in AD

Hi, i don't manage to find an exemple of creating Subnet script.
It's more special than creat just simple user, it's on the
configuration partition so i'm not sure...
If someone could help me I try to make a script which search subnet
too...

Thanks !

--
P.A.


My System SpecsSystem Spec
Old 09-14-2007   #2 (permalink)
Brandon Shell


 
 

Re: Create a subnet in AD

Try this, for some odd reason I had to specifically set the DN, but I did
and it worked...

###############
function Add-ADSubnet{
Param($NetMask,$Site)
$root = [ADSI]"LDAP://rootDSE"
$conf = $root.configurationNamingContext
$subnetcont = [ADSI]"LDAP://CN=Subnets,CN=Sites,$conf"
$subnetcont.psbase.children
$subnetobj = $subnetcont.create('subnet',"cn=$netmask")
$subnetobj.put("siteObject","cn=$site,CN=Sites,$conf")
$subnetobj.put("distinguishedName","CN=$netmask,CN=Subnets,CN=Sites,$conf")
$subnetobj.setinfo()
}
Add-ADSubnet "10.10.10.0/23" -site "MySite"

"BZP" <p.audonnet@xxxxxx> wrote in message
news:1189764786.080205.264730@xxxxxx
Quote:

> Hi, i don't manage to find an exemple of creating Subnet script.
> It's more special than creat just simple user, it's on the
> configuration partition so i'm not sure...
> If someone could help me I try to make a script which search subnet
> too...
>
> Thanks !
>
> --
> P.A.
>
My System SpecsSystem Spec
Old 09-14-2007   #3 (permalink)
Shay Levi


 
 

Re: Create a subnet in AD

I also tried to create it, I got stuck with the following (Your code outputs
the same
on my lab DC - W3K SP1)

Exception calling "setinfo" with "0" argument(s): "A constraint violation
occurred. (Exception from HRESULT: 0x8007202F
)"
At line:10 char:19
+ $subnetobj.setinfo( <<<< )


Shay
http://scriptolog.blogspot.com


Quote:

> Try this, for some odd reason I had to specifically set the DN, but I
> did and it worked...
>
> ###############
> function Add-ADSubnet{
> Param($NetMask,$Site)
> $root = [ADSI]"LDAP://rootDSE"
> $conf = $root.configurationNamingContext
> $subnetcont = [ADSI]"LDAP://CN=Subnets,CN=Sites,$conf"
> $subnetcont.psbase.children
> $subnetobj = $subnetcont.create('subnet',"cn=$netmask")
> $subnetobj.put("siteObject","cn=$site,CN=Sites,$conf")
>
> $subnetobj.put("distinguishedName","CN=$netmask,CN=Subnets,CN=Sites,$c
> onf")
> $subnetobj.setinfo()
> }
> Add-ADSubnet "10.10.10.0/23" -site "MySite"
>
> "BZP" <p.audonnet@xxxxxx> wrote in message
> news:1189764786.080205.264730@xxxxxx
>
Quote:

>> Hi, i don't manage to find an exemple of creating Subnet script.
>> It's more special than creat just simple user, it's on the
>> configuration partition so i'm not sure...
>> If someone could help me I try to make a script which search
>> subnet
>> too...
>> Thanks !
>>
>> --
>> P.A.

My System SpecsSystem Spec
Old 09-14-2007   #4 (permalink)
Brandon Shell


 
 

Re: Create a subnet in AD

Odd.. I tried in both my Labs and in production Also.. you have to be
logged as an Enterprise Admin.

What happens if you Hardcode the LDAP paths
$root = [ADSI]"LDAP://<SERVER>/rootDSE"

"Shay Levi" <no@xxxxxx> wrote in message
news:8766a94473128c9c50edad7e9a4@xxxxxx
Quote:

>I also tried to create it, I got stuck with the following (Your code
>outputs the same
> on my lab DC - W3K SP1)
>
> Exception calling "setinfo" with "0" argument(s): "A constraint violation
> occurred. (Exception from HRESULT: 0x8007202F
> )"
> At line:10 char:19
> + $subnetobj.setinfo( <<<< )
>
>
> Shay
> http://scriptolog.blogspot.com
>
>
>
Quote:

>> Try this, for some odd reason I had to specifically set the DN, but I
>> did and it worked...
>>
>> ###############
>> function Add-ADSubnet{
>> Param($NetMask,$Site)
>> $root = [ADSI]"LDAP://rootDSE"
>> $conf = $root.configurationNamingContext
>> $subnetcont = [ADSI]"LDAP://CN=Subnets,CN=Sites,$conf"
>> $subnetcont.psbase.children
>> $subnetobj = $subnetcont.create('subnet',"cn=$netmask")
>> $subnetobj.put("siteObject","cn=$site,CN=Sites,$conf")
>>
>> $subnetobj.put("distinguishedName","CN=$netmask,CN=Subnets,CN=Sites,$c
>> onf")
>> $subnetobj.setinfo()
>> }
>> Add-ADSubnet "10.10.10.0/23" -site "MySite"
>>
>> "BZP" <p.audonnet@xxxxxx> wrote in message
>> news:1189764786.080205.264730@xxxxxx
>>
Quote:

>>> Hi, i don't manage to find an exemple of creating Subnet script.
>>> It's more special than creat just simple user, it's on the
>>> configuration partition so i'm not sure...
>>> If someone could help me I try to make a script which search
>>> subnet
>>> too...
>>> Thanks !
>>>
>>> --
>>> P.A.
>
>
My System SpecsSystem Spec
Old 09-14-2007   #5 (permalink)
Brandon Shell


 
 

Re: Create a subnet in AD

Like I said... You shouldn't need this line
$subnetobj.put("distinguishedName","CN=$netmask....

What happens when you remove it.

FYI: In all three tested environments I am using win2k3 SP2

"Shay Levi" <no@xxxxxx> wrote in message
news:8766a944734f8c9c5168c2261e2@xxxxxx
Quote:

> Same error.
>
> Shay
> http://scriptolog.blogspot.com
>
>
>
Quote:

>> Odd.. I tried in both my Labs and in production Also.. you have to
>> be logged as an Enterprise Admin.
>>
>> What happens if you Hardcode the LDAP paths
>> $root = [ADSI]"LDAP://<SERVER>/rootDSE"
>> "Shay Levi" <no@xxxxxx> wrote in message
>> news:8766a94473128c9c50edad7e9a4@xxxxxx
>>
Quote:

>>> I also tried to create it, I got stuck with the following (Your code
>>> outputs the same
>>> on my lab DC - W3K SP1)
>>> Exception calling "setinfo" with "0" argument(s): "A constraint
>>> violation
>>> occurred. (Exception from HRESULT: 0x8007202F
>>> )"
>>> At line:10 char:19
>>> + $subnetobj.setinfo( <<<< )
>>> Shay
>>> http://scriptolog.blogspot.com
>>>> Try this, for some odd reason I had to specifically set the DN, but
>>>> I did and it worked...
>>>>
>>>> ###############
>>>> function Add-ADSubnet{
>>>> Param($NetMask,$Site)
>>>> $root = [ADSI]"LDAP://rootDSE"
>>>> $conf = $root.configurationNamingContext
>>>> $subnetcont = [ADSI]"LDAP://CN=Subnets,CN=Sites,$conf"
>>>> $subnetcont.psbase.children
>>>> $subnetobj = $subnetcont.create('subnet',"cn=$netmask")
>>>> $subnetobj.put("siteObject","cn=$site,CN=Sites,$conf")
>>>> $subnetobj.put("distinguishedName","CN=$netmask,CN=Subnets,CN=Sites,
>>>> $c
>>>> onf")
>>>> $subnetobj.setinfo()
>>>> }
>>>> Add-ADSubnet "10.10.10.0/23" -site "MySite"
>>>> "BZP" <p.audonnet@xxxxxx> wrote in message
>>>> news:1189764786.080205.264730@xxxxxx
>>>>> Hi, i don't manage to find an exemple of creating Subnet script.
>>>>> It's more special than creat just simple user, it's on the
>>>>> configuration partition so i'm not sure...
>>>>> If someone could help me I try to make a script which search
>>>>> subnet
>>>>> too...
>>>>> Thanks !
>>>>> --
>>>>> P.A.
>
>
My System SpecsSystem Spec
Old 09-14-2007   #6 (permalink)
Shay Levi


 
 

Re: Create a subnet in AD

Same error.

Shay
http://scriptolog.blogspot.com


Quote:

> Odd.. I tried in both my Labs and in production Also.. you have to
> be logged as an Enterprise Admin.
>
> What happens if you Hardcode the LDAP paths
> $root = [ADSI]"LDAP://<SERVER>/rootDSE"
> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a94473128c9c50edad7e9a4@xxxxxx
>
Quote:

>> I also tried to create it, I got stuck with the following (Your code
>> outputs the same
>> on my lab DC - W3K SP1)
>> Exception calling "setinfo" with "0" argument(s): "A constraint
>> violation
>> occurred. (Exception from HRESULT: 0x8007202F
>> )"
>> At line:10 char:19
>> + $subnetobj.setinfo( <<<< )
>> Shay
>> http://scriptolog.blogspot.com
Quote:

>>> Try this, for some odd reason I had to specifically set the DN, but
>>> I did and it worked...
>>>
>>> ###############
>>> function Add-ADSubnet{
>>> Param($NetMask,$Site)
>>> $root = [ADSI]"LDAP://rootDSE"
>>> $conf = $root.configurationNamingContext
>>> $subnetcont = [ADSI]"LDAP://CN=Subnets,CN=Sites,$conf"
>>> $subnetcont.psbase.children
>>> $subnetobj = $subnetcont.create('subnet',"cn=$netmask")
>>> $subnetobj.put("siteObject","cn=$site,CN=Sites,$conf")
>>> $subnetobj.put("distinguishedName","CN=$netmask,CN=Subnets,CN=Sites,
>>> $c
>>> onf")
>>> $subnetobj.setinfo()
>>> }
>>> Add-ADSubnet "10.10.10.0/23" -site "MySite"
>>> "BZP" <p.audonnet@xxxxxx> wrote in message
>>> news:1189764786.080205.264730@xxxxxx
>>>> Hi, i don't manage to find an exemple of creating Subnet script.
>>>> It's more special than creat just simple user, it's on the
>>>> configuration partition so i'm not sure...
>>>> If someone could help me I try to make a script which search
>>>> subnet
>>>> too...
>>>> Thanks !
>>>> --
>>>> P.A.

My System SpecsSystem Spec
Old 09-14-2007   #7 (permalink)
Brandon Shell


 
 

Re: Create a subnet in AD

I have one more place I can test it is Win2k3 SP1... I will post the
results.

"Brandon Shell" <tshell.mask@xxxxxx> wrote in message
news:e75xhcu9HHA.1208@xxxxxx
Quote:

> Like I said... You shouldn't need this line
> $subnetobj.put("distinguishedName","CN=$netmask....
>
> What happens when you remove it.
>
> FYI: In all three tested environments I am using win2k3 SP2
>
> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a944734f8c9c5168c2261e2@xxxxxx
Quote:

>> Same error.
>>
>> Shay
>> http://scriptolog.blogspot.com
>>
>>
>>
Quote:

>>> Odd.. I tried in both my Labs and in production Also.. you have to
>>> be logged as an Enterprise Admin.
>>>
>>> What happens if you Hardcode the LDAP paths
>>> $root = [ADSI]"LDAP://<SERVER>/rootDSE"
>>> "Shay Levi" <no@xxxxxx> wrote in message
>>> news:8766a94473128c9c50edad7e9a4@xxxxxx
>>>
>>>> I also tried to create it, I got stuck with the following (Your code
>>>> outputs the same
>>>> on my lab DC - W3K SP1)
>>>> Exception calling "setinfo" with "0" argument(s): "A constraint
>>>> violation
>>>> occurred. (Exception from HRESULT: 0x8007202F
>>>> )"
>>>> At line:10 char:19
>>>> + $subnetobj.setinfo( <<<< )
>>>> Shay
>>>> http://scriptolog.blogspot.com
>>>>> Try this, for some odd reason I had to specifically set the DN, but
>>>>> I did and it worked...
>>>>>
>>>>> ###############
>>>>> function Add-ADSubnet{
>>>>> Param($NetMask,$Site)
>>>>> $root = [ADSI]"LDAP://rootDSE"
>>>>> $conf = $root.configurationNamingContext
>>>>> $subnetcont = [ADSI]"LDAP://CN=Subnets,CN=Sites,$conf"
>>>>> $subnetcont.psbase.children
>>>>> $subnetobj = $subnetcont.create('subnet',"cn=$netmask")
>>>>> $subnetobj.put("siteObject","cn=$site,CN=Sites,$conf")
>>>>> $subnetobj.put("distinguishedName","CN=$netmask,CN=Subnets,CN=Sites,
>>>>> $c
>>>>> onf")
>>>>> $subnetobj.setinfo()
>>>>> }
>>>>> Add-ADSubnet "10.10.10.0/23" -site "MySite"
>>>>> "BZP" <p.audonnet@xxxxxx> wrote in message
>>>>> news:1189764786.080205.264730@xxxxxx
>>>>>> Hi, i don't manage to find an exemple of creating Subnet script.
>>>>>> It's more special than creat just simple user, it's on the
>>>>>> configuration partition so i'm not sure...
>>>>>> If someone could help me I try to make a script which search
>>>>>> subnet
>>>>>> too...
>>>>>> Thanks !
>>>>>> --
>>>>>> P.A.
>>
>>
>
My System SpecsSystem Spec
Old 09-14-2007   #8 (permalink)
Brandon Shell


 
 

Re: Create a subnet in AD

worked in my win2k3 SP1 environment as well.

So I have test it in 3 SP2 and 1 SP1... they all work. Curious yours doesnt
Shay.

"Brandon Shell" <tshell.mask@xxxxxx> wrote in message
news:uJfxHgu9HHA.5456@xxxxxx
Quote:

>I have one more place I can test it is Win2k3 SP1... I will post the
>results.
>
> "Brandon Shell" <tshell.mask@xxxxxx> wrote in message
> news:e75xhcu9HHA.1208@xxxxxx
Quote:

>> Like I said... You shouldn't need this line
>> $subnetobj.put("distinguishedName","CN=$netmask....
>>
>> What happens when you remove it.
>>
>> FYI: In all three tested environments I am using win2k3 SP2
>>
>> "Shay Levi" <no@xxxxxx> wrote in message
>> news:8766a944734f8c9c5168c2261e2@xxxxxx
Quote:

>>> Same error.
>>>
>>> Shay
>>> http://scriptolog.blogspot.com
>>>
>>>
>>>
>>>> Odd.. I tried in both my Labs and in production Also.. you have to
>>>> be logged as an Enterprise Admin.
>>>>
>>>> What happens if you Hardcode the LDAP paths
>>>> $root = [ADSI]"LDAP://<SERVER>/rootDSE"
>>>> "Shay Levi" <no@xxxxxx> wrote in message
>>>> news:8766a94473128c9c50edad7e9a4@xxxxxx
>>>>
>>>>> I also tried to create it, I got stuck with the following (Your code
>>>>> outputs the same
>>>>> on my lab DC - W3K SP1)
>>>>> Exception calling "setinfo" with "0" argument(s): "A constraint
>>>>> violation
>>>>> occurred. (Exception from HRESULT: 0x8007202F
>>>>> )"
>>>>> At line:10 char:19
>>>>> + $subnetobj.setinfo( <<<< )
>>>>> Shay
>>>>> http://scriptolog.blogspot.com
>>>>>> Try this, for some odd reason I had to specifically set the DN, but
>>>>>> I did and it worked...
>>>>>>
>>>>>> ###############
>>>>>> function Add-ADSubnet{
>>>>>> Param($NetMask,$Site)
>>>>>> $root = [ADSI]"LDAP://rootDSE"
>>>>>> $conf = $root.configurationNamingContext
>>>>>> $subnetcont = [ADSI]"LDAP://CN=Subnets,CN=Sites,$conf"
>>>>>> $subnetcont.psbase.children
>>>>>> $subnetobj = $subnetcont.create('subnet',"cn=$netmask")
>>>>>> $subnetobj.put("siteObject","cn=$site,CN=Sites,$conf")
>>>>>> $subnetobj.put("distinguishedName","CN=$netmask,CN=Subnets,CN=Sites,
>>>>>> $c
>>>>>> onf")
>>>>>> $subnetobj.setinfo()
>>>>>> }
>>>>>> Add-ADSubnet "10.10.10.0/23" -site "MySite"
>>>>>> "BZP" <p.audonnet@xxxxxx> wrote in message
>>>>>> news:1189764786.080205.264730@xxxxxx
>>>>>>> Hi, i don't manage to find an exemple of creating Subnet script.
>>>>>>> It's more special than creat just simple user, it's on the
>>>>>>> configuration partition so i'm not sure...
>>>>>>> If someone could help me I try to make a script which search
>>>>>>> subnet
>>>>>>> too...
>>>>>>> Thanks !
>>>>>>> --
>>>>>>> P.A.
>>>
>>>
>>
>
My System SpecsSystem Spec
Old 09-14-2007   #9 (permalink)
Brandon Shell


 
 

Re: Create a subnet in AD

btw... I just looked at your error... that is because it actually verifies
the IP/Mask fit

try 10.0.0.0/24

"Shay Levi" <no@xxxxxx> wrote in message
news:8766a944734f8c9c5168c2261e2@xxxxxx
Quote:

> Same error.
>
> Shay
> http://scriptolog.blogspot.com
>
>
>
Quote:

>> Odd.. I tried in both my Labs and in production Also.. you have to
>> be logged as an Enterprise Admin.
>>
>> What happens if you Hardcode the LDAP paths
>> $root = [ADSI]"LDAP://<SERVER>/rootDSE"
>> "Shay Levi" <no@xxxxxx> wrote in message
>> news:8766a94473128c9c50edad7e9a4@xxxxxx
>>
Quote:

>>> I also tried to create it, I got stuck with the following (Your code
>>> outputs the same
>>> on my lab DC - W3K SP1)
>>> Exception calling "setinfo" with "0" argument(s): "A constraint
>>> violation
>>> occurred. (Exception from HRESULT: 0x8007202F
>>> )"
>>> At line:10 char:19
>>> + $subnetobj.setinfo( <<<< )
>>> Shay
>>> http://scriptolog.blogspot.com
>>>> Try this, for some odd reason I had to specifically set the DN, but
>>>> I did and it worked...
>>>>
>>>> ###############
>>>> function Add-ADSubnet{
>>>> Param($NetMask,$Site)
>>>> $root = [ADSI]"LDAP://rootDSE"
>>>> $conf = $root.configurationNamingContext
>>>> $subnetcont = [ADSI]"LDAP://CN=Subnets,CN=Sites,$conf"
>>>> $subnetcont.psbase.children
>>>> $subnetobj = $subnetcont.create('subnet',"cn=$netmask")
>>>> $subnetobj.put("siteObject","cn=$site,CN=Sites,$conf")
>>>> $subnetobj.put("distinguishedName","CN=$netmask,CN=Subnets,CN=Sites,
>>>> $c
>>>> onf")
>>>> $subnetobj.setinfo()
>>>> }
>>>> Add-ADSubnet "10.10.10.0/23" -site "MySite"
>>>> "BZP" <p.audonnet@xxxxxx> wrote in message
>>>> news:1189764786.080205.264730@xxxxxx
>>>>> Hi, i don't manage to find an exemple of creating Subnet script.
>>>>> It's more special than creat just simple user, it's on the
>>>>> configuration partition so i'm not sure...
>>>>> If someone could help me I try to make a script which search
>>>>> subnet
>>>>> too...
>>>>> Thanks !
>>>>> --
>>>>> P.A.
>
>
My System SpecsSystem Spec
Old 09-14-2007   #10 (permalink)
Brandon Shell


 
 

Re: Create a subnet in AD

After so rework.. this is a better solution

function Add-ADSubnetObject{
Param($NetMask,$Site)
$root = [ADSI]"LDAP://rootDSE"
$conf = $root.configurationNamingContext
$subnetcont = [ADSI]"LDAP://CN=Subnets,CN=Sites,$conf"
$subnetobj = $subnetcont.create('subnet',"cn=$netmask")
$subnetobj.put("siteObject","cn=$site,CN=Sites,$conf")
$subnetobj.setinfo()
}

Add-ADSubnetObject -netmask "10.10.10.0/24" -site "MySite"

"BZP" <p.audonnet@xxxxxx> wrote in message
news:1189764786.080205.264730@xxxxxx
Quote:

> Hi, i don't manage to find an exemple of creating Subnet script.
> It's more special than creat just simple user, it's on the
> configuration partition so i'm not sure...
> If someone could help me I try to make a script which search subnet
> too...
>
> Thanks !
>
> --
> P.A.
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Script to run only on a given subnet VB Script
Windows browsing in an IP subnet with no DC .NET General
Vista sharing and subnet Vista networking & sharing
IPSec: IP-Rule with subnet Vista networking & sharing
subnet problem Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46