Skip to content

ConvertTo-CSharp

SYNOPSIS

Converts PowerShell script to C# code.

SYNTAX

PathByPipeline

ConvertTo-CSharp -PowerShellScriptFile <FileInfo> [<CommonParameters>]

Path

ConvertTo-CSharp -PowerShellScriptPath <String> [<CommonParameters>]

Text

ConvertTo-CSharp -PowerShellScript <String> [<CommonParameters>]

ScriptBlock

ConvertTo-CSharp -ScriptBlock <ScriptBlock> [<CommonParameters>]

DESCRIPTION

Converts PowerShell script to C# code. You can specify a path, PowerShell script text or a PowerShell script block.

EXAMPLES

Example 1

PS C:\> ConvertTo-CSharp -PowerShellScriptPath .\*.ps1

Converts all PS1 files in the current directory to C# code. Returns an array of the contents of the files.

Example 2

PS C:\> ConvertTo-CSharp -PowerShellScript "Get-Process"

Converts the specified PowerShell script to C# code.

Example 3

PS C:\> ConvertTo-CSharp -ScriptBlock { Get-Process }

Converts the specified PowerShell ScriptBlock to C# code.

Example 4

PS C:\> Get-ChildItem .\*.ps1 | ConvertTo-CSharp

Converts the piped PS1 files to C#

PARAMETERS

-PowerShellScriptFile

A FileInfo for a PS1 or PSM1

Type: System.IO.FileInfo
Parameter Sets: PathByPipeline
Aliases:

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

-PowerShellScript

The contents of a PowerShell script

Type: System.String
Parameter Sets: Text
Aliases:

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

-PowerShellScriptPath

The path to a PS1 or PSM1 file.

Type: System.String
Parameter Sets: Path
Aliases:

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

-ScriptBlock

A PowerShell ScriptBlock

Type: System.Management.Automation.ScriptBlock
Parameter Sets: ScriptBlock
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
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

System.String

System.Management.Automation.ScriptBlock

OUTPUTS

System.String

NOTES

Back to top