Skip to content

Latest commit

 

History

History
212 lines (151 loc) · 5.22 KB

File metadata and controls

212 lines (151 loc) · 5.22 KB
external help file Module Name ms.date schema title
AdminUI.PS.dll-Help.xml
ConfigurationManager
12/28/2021
2.0.0
Approve-CMScript

Approve-CMScript

SYNOPSIS

Approve a PowerShell script in Configuration Manager.

SYNTAX

ByScript

Approve-CMScript [-Comment <String>] -InputObject <IResultObject> [-DisableWildcardHandling]
 [-ForceWildcardHandling] [-WhatIf] [-Confirm] [<CommonParameters>]

ByScriptId

Approve-CMScript [-Comment <String>] -ScriptGuid <String> [-DisableWildcardHandling] [-ForceWildcardHandling]
 [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

Use this cmdlet to approve a Powershell script in Configuration Manager. These scripts are integrated and managed in Configuration Manager. You can't run a script on devices until it's approved. After you approve a script, to run it use the Invoke-CMScript cmdlet.

By default, you can't approve scripts that you author.

For more information, see Create and run PowerShell scripts from the Configuration Manager console.

Note

Run Configuration Manager cmdlets from the Configuration Manager site drive, for example PS XYZ:\>. For more information, see getting started.

EXAMPLES

Example 1: Approve a script by using the script ID

This command approves a script that has the ID DF8E7546-FD66-4A3D-A129-53AF5AA54F80.

Approve-CMScript -ScriptGuid "DF8E7546-FD66-4A3D-A129-53AF5AA54F80"

Example 2: Approve a script by using script object variable

The first command gets a script object with ID DF8E7546-FD66-4A3D-A129-53AF5AA54F80. It then stores the object in the $ScriptObj variable.

The second command approves the script stored in the variable.

$ScriptObj = Get-CMScript -Id "DF8E7546-FD66-4A3D-A129-53AF5AA54F80"
Approve-CMScript -InputObject $ScriptObj

Example 3: Bulk approve all unapproved scripts

This command gets all scripts in Configuration Manager that aren't approved. It then loops through each script in the scripts array. If the current user is not the author of the script, it approves it.

$scripts = Get-CMScript -Fast | Where-Object { -not $_.ApprovalState }

$me = $env:userdomain + "\" + $env:username
foreach ( $script in $scripts ) {
  if ( $script.Author -ne $me ) {
    Approve-CMScript -InputObject $script
  }
}

PARAMETERS

-Comment

Specifies a comment about the approval of the script.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-DisableWildcardHandling

This parameter treats wildcard characters as literal character values. You can't combine it with ForceWildcardHandling.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ForceWildcardHandling

This parameter processes wildcard characters and may lead to unexpected behavior (not recommended). You can't combine it with DisableWildcardHandling.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-InputObject

Specify a script object to approve. To get this object, use the Get-CMScript cmdlet.

Type: IResultObject
Parameter Sets: ByScript
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-ScriptGuid

Specify the ID of the script to approve. The format is a standard GUID.

Type: String
Parameter Sets: ByScriptId
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet doesn't run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

Microsoft.ConfigurationManagement.ManagementProvider.IResultObject

OUTPUTS

System.Object

NOTES

RELATED LINKS

Deny-CMScript Get-CMScript Invoke-CMScript New-CMScript Remove-CMScript Set-CMScript

Create and run PowerShell scripts from the Configuration Manager console