Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Whats the correct format of the New-SPWeb command when using the UseParentTopNav argument?

I'm trying to add a new site, I've tried passing in the following

New-SPWeb -url "http://server" -Template "STS#0" -Name "test99" -Description "test99"  -UseParentTopNav 1      

and

New-SPWeb -url "http://server" -Template "STS#0" -Name "test99" -Description "test99"  -UseParentTopNav true

they both give error message

New-SPWeb : A positional parameter cannot be found that accepts argument '1'.
At line:2 char:11
+  New-SPWeb <<<<  -url "http:/server" -Template "STS#0" -Name "test99" -Description "test99"  -UseParentTopNav 1
    + CategoryInfo          : InvalidArgument: (:) [New-SPWeb], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.SharePoint.PowerShell.SPCmdletNewWeb

and

New-SPWeb : A positional parameter cannot be found that accepts argument 'true'.
At line:3 char:11
+  New-SPWeb <<<<  -url "http://onlm45005wkhxn1:33333" -Template "STS#0" -Name "test99" -Description "test99"  -UseParentTopNav true
    + CategoryInfo          : InvalidArgument: (:) [New-SPWeb], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.SharePoint.PowerShell.SPCmdletNewWeb

If I run the help command

get-help New-SPWeb -full

it gives me this information.

-UseParentTopNav <SwitchParameter>
    Specifies that the same top-level navigation bar as the parent site is to be used for this site.
    Required?                    false
    Position?                    Named
    Default value                
    Accept pipeline input?       False
    Accept wildcard characters?  false

What format should the <SwitchParameter> be?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

Switch parameters just need to be by themself, no argument is needed:

New-SPWeb -url "http://server" -Template "STS#0" -Name "test99" -Description "test99" -UseParentTopNav

http://msdn.microsoft.com/en-us/library/system.management.automation.switchparameter(v=vs.85).aspx

A switch parameter is a parameter that may, or may not, be specified when the command is run. If the parameter is specified, the Windows PowerShell runtime resolves its value as true. If the parameter is not specified, which is typically the default, the parameter value is resolved as false.

share|improve this answer
1  
thanks I got it to work by using -UseParentTopNav:$true . But good to know the $true isnt necessary either. –  gotsp Apr 21 '11 at 1:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.