external help file | online version | schema |
---|---|---|
PowerShellEditorServices.Commands-help.xml |
2.0.0 |
Replaces text at a specified IScriptExtent object.
Set-ScriptExtent [-Text] <PSObject> [-Extent <IScriptExtent>] [<CommonParameters>]
Set-ScriptExtent [-Text] <PSObject> [-AsString] [-Extent <IScriptExtent>] [<CommonParameters>]
Set-ScriptExtent [-Text] <PSObject> [-AsArray] [-Extent <IScriptExtent>] [<CommonParameters>]
The Set-ScriptExtent function can insert or replace text at a specified position in a file open in PowerShell Editor Services.
You can use the Find-Ast function to easily find the desired extent.
Find-Ast { 'gci' -eq $_ } | Set-ScriptExtent -Text 'Get-ChildItem'
Replaces all instances of 'gci' with 'Get-ChildItem'
$manifestAst = Find-Ast { 'FunctionsToExport' -eq $_ } | Find-Ast -First
$manifestAst | Set-ScriptExtent -Text (gci .\src\Public).BaseName -AsArray
Replaces the current value of FunctionsToExport in a module manifest with a list of files in the Public folder as a string array literal expression.
Specifies the text to insert in place of the extent. Any object can be specified, but will be converted to a string before being passed to PowerShell Editor Services.
Type: PSObject
Parameter Sets: (All)
Aliases: Value
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Specifies to insert as a single quoted string expression.
Type: SwitchParameter
Parameter Sets: AsString
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Specifies to insert as a single quoted string list. The list is separated by comma and new line, and will be adjusted to a hanging indent.
Type: SwitchParameter
Parameter Sets: AsArray
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Specifies the extent to replace within the editor.
Type: IScriptExtent
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: (Find-Ast -AtCursor).Extent
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
You can pass ScriptExtent objects to this function. You can also pass objects with a property named "Extent" such as ASTs from Find-Ast or tokens from Get-Token.
Find-Ast ConvertTo-ScriptExtent ConvertFrom-ScriptExtent Test-ScriptExtent Join-ScriptExtent