Get-CMScript

Get a PowerShell script in Configuration Manager.

Syntax

Get-CMScript
   [-Author <String>]
   [-Fast]
   [-ScriptName <String>]
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [<CommonParameters>]
Get-CMScript
   [-Author <String>]
   [-Fast]
   -ScriptGuid <String>
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [<CommonParameters>]

Description

Use this cmdlet to get a Configuration Manager PowerShell script. These scripts are integrated and managed in Configuration Manager. 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: Get all unapproved scripts

This command gets all scripts in Configuration Manager that aren't approved.

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

Example 2: Get scripts by using name

This command gets all scripts that have a name that begins with the letter D.

Get-CMScript -ScriptName "D*"

Example 3: Get scripts from a specific author

This command gets all scripts for the author with username jqpublic. Since it uses the asterisk (*) wildcard, the specific domain doesn't matter. It then returns a table that lists the script name, approval state, and last update time.

Get-CMScript -Fast -Author "*jqpublic" | Select-Object ScriptName, ApprovalState, LastUpdateTime

Parameters

-Author

Specify the author of the script to get. For example, contoso\jqpublic.

You can use wildcard characters:

  • *: Multiple characters
  • ?: Single character
Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

-DisableWildcardHandling

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

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

-Fast

Add this parameter to not automatically refresh lazy properties. Lazy properties contain values that are relatively inefficient to retrieve. Getting these properties can cause additional network traffic and decrease cmdlet performance.

If you don't use this parameter, the cmdlet displays a warning. To disable this warning, set $CMPSSuppressFastNotUsedCheck = $true.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
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
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ScriptGuid

Applies to version 2010 and later. Specify the GUID of a script to get.

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

-ScriptName

Specify a script name to get.

You can use wildcard characters:

  • *: Multiple characters
  • ?: Single character
Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

Inputs

None

Outputs

IResultObject[]

IResultObject

Notes

This cmdlet returns an object for the SMS_Scripts WMI class.