Open-NetGPO

Open-NetGPO

Creates a cached copy of the Group Policy Object (GPO) to modify locally.

Syntax

Parameter Set: Open0
Open-NetGPO [-PolicyStore] <String> [-AsJob] [-CimSession <CimSession[]> ] [-DomainController <String> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]

Detailed Description

The Open-NetGPO cmdlet caches the Group Policy Object (GPO) so that modifications can be made locally. The changes are batch returned to the policy store with the Save-NetGPO cmdlet.

Note: If the DomainController parameter value is not a writeable Domain Controller (DC), then the batch updates will not be applied. To help target a writeable DC, use the cmdlets in the Active Directory module using the Get-Command cmdlet with the Module parameter set to ActiveDirectory.

Note: An error will result for using this cmdlet when the user is not a domain administrator.

Parameters

-AsJob

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-CimSession<CimSession[]>

Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-DomainController<String>

Specifies the DC used to target the GPO. If this cmdlet is used without specifying this parameter, then the DC can target a read-only DC (RODC), and lose the batch changes with Save-NetGPO. To help target a writeable DC, use the cmdlets in the Active Directory module using the Get-Command cmdlet with the Module parameter set to ActiveDirectory.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-PolicyStore<String>

Specifies the policy store from which to retrieve the rules to be stored.
A policy store is a container for firewall and IPsec policy.
The acceptable values for this parameter are:
-- PersistentStore: Sometimes called static rules, this store contains the persistent policy for the local computer. This policy is not from GPOs, and has been created manually or programmatically (during application installation) on the computer. Rules created in this store are attached to the ActiveStore and activated on the computer immediately.
-- ActiveStore: This store contains the currently active policy, which is the sum of all policy stores that apply to the computer. This is the resultant set of policy (RSOP) for the local computer (the sum of all GPOs that apply to the computer), and the local stores (the PersistentStore, the static Windows service hardening (WSH), and the configurable WSH).
-- -- GPOs are also policy stores. Computer GPOs can be specified as follows.
--- -- –PolicyStore hostname.
-- -- Active Directory GPOs can be specified as follows.
--- -- –PolicyStore domain.fqdn.com\GPO_Friendly_Namedomain.fqdn.comGPO_Friendly_Name.
--- -- Such as the following.
--- -- -- -PolicyStore localhost
--- -- -- -PolicyStore corp.contoso.com\FirewallPolicy
-- -- Active Directory GPOs can be created using the New-GPO cmdlet or the Group Policy Management Console.
-- RSOP: This read-only store contains the sum of all GPOs applied to the local computer.
-- SystemDefaults: This read-only store contains the default state of firewall rules that ship with Windows Server 2012.
-- StaticServiceStore: This read-only store contains all the service restrictions that ship with Windows Server 2012. Optional and product-dependent features are considered part of Windows Server 2012 for the purposes of WFAS.
-- ConfigurableServiceStore: This read-write store contains all the service restrictions that are added for third-party services. In addition, network isolation rules that are created for Windows Store application containers will appear in this policy store.
The default value is PersistentStore.
Note: The Set-NetIPsecRule cmdlet cannot be used to add an object to a policy store. An object can only be added to a policy store at creation time with this Copy-NetIPsecRule cmdlet or with the New-NetIPsecRule cmdlet.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ThrottleLimit<Int32>

Specifies the maximum number of concurrent operations that can be established to run the cmdlet. If this parameter is omitted or a value of 0 is entered, then Windows PowerShell® calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies only to the current cmdlet, not to the session or to the computer.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • None

Outputs

The output type is the type of the objects that the cmdlet emits.

  • Microsoft.Management.Infrastructure.CimInstance#root\StandardCimv2\GPOSession

    The Microsoft.Management.Infrastructure.CimInstance object is a wrapper class that displays Windows Management Instrumentation (WMI) objects. The path after the pound sign (#) provides the namespace and class name for the underlying WMI object.

Examples

EXAMPLE 1

This example replaces one rule in a domain GPO with another using a cached copy of the GPO.

PS C:\> $gpoSession = Open-NetGPO –PolicyStore castle.contoso.com\Win8ClientFirewallPolicy
PS C:\> Remove-NetFirewallRule –Name BlockIMAccess –GPOSession $gpoSession
PS C:\> New-NetFirewallRule –Name LimitIMAccess –DisplayName "Contoso Messenger" –Program "%ProgramFiles(X86)%\Contoso Messenger\cmsg.exe" –Action Block –GPOSession $gpoSession
PS C:\> Save-NetGPO –GPOSession $gpoSession

EXAMPLE 2

This example shows targeting and opening a writeable DC. This ensures that the batch modifications are made when the GPO is closed.

PS C:\> $domain = "corp.contoso.com"
PS C:\> $gpo = "corp.contoso.com\FirewallPolicy"
PS C:\> $pdc = Get-ADDomainController -Discover -Service PrimaryDC -DomainName $domain
PS C:\> $session = Open-NetGPO -PolicyStore $gpo -DomainController $pdc.Hostname

New-NetFirewallRule

Remove-NetFirewallRule

Save-NetGPO

New-NetIPsecRule

Set-NetIPsecRule

Get-ADDomainController

New-GPO

Get-Command