ConvertTo-CSharp

SYNOPSIS

Converts PowerShell script to C# code.

SYNTAX

PathByPipeline

1
ConvertTo-CSharp -PowerShellScriptFile <FileInfo>
Copied!

Path

1
ConvertTo-CSharp -PowerShellScriptPath <String>
Copied!

Text

1
ConvertTo-CSharp -PowerShellScript <String>
Copied!

ScriptBlock

1
ConvertTo-CSharp -ScriptBlock <ScriptBlock>
Copied!

DESCRIPTION

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

EXAMPLES

Example 1

1
PS C:\> ConvertTo-CSharp -PowerShellScriptPath .\*.ps1
Copied!
Converts all PS1 files in the current directory to C# code. Returns an array of the contents of the files.

Example 2

1
PS C:\> ConvertTo-CSharp -PowerShellScript "Get-Process"
Copied!
Converts the specified PowerShell script to C# code.

Example 3

1
PS C:\> ConvertTo-CSharp -ScriptBlock { Get-Process }
Copied!
Converts the specified PowerShell ScriptBlock to C# code.

Example 4

1
PS C:\> Get-ChildItem .\*.ps1 | ConvertTo-CSharp
Copied!
Converts the piped PS1 files to C#

PARAMETERS

-PowerShellScriptFile

A FileInfo for a PS1 or PSM1
1
Type: FileInfo
2
Parameter Sets: PathByPipeline
3
Aliases:
4
5
Required: True
6
Position: Named
7
Default value: None
8
Accept pipeline input: True (ByValue)
9
Accept wildcard characters: False
Copied!

-PowerShellScript

The contents of a PowerShell script
1
Type: String
2
Parameter Sets: Text
3
Aliases:
4
5
Required: True
6
Position: Named
7
Default value: None
8
Accept pipeline input: True (ByValue)
9
Accept wildcard characters: False
Copied!

-PowerShellScriptPath

The path to a PS1 or PSM1 file.
1
Type: String
2
Parameter Sets: Path
3
Aliases:
4
5
Required: True
6
Position: Named
7
Default value: None
8
Accept pipeline input: False
9
Accept wildcard characters: True
Copied!

-ScriptBlock

A PowerShell ScriptBlock
1
Type: ScriptBlock
2
Parameter Sets: ScriptBlock
3
Aliases:
4
5
Required: True
6
Position: Named
7
Default value: None
8
Accept pipeline input: True (ByValue)
9
Accept wildcard characters: False
Copied!

INPUTS

System.String

System.Management.Automation.ScriptBlock

OUTPUTS

System.String

NOTES

RELATED LINKS

Last modified 2yr ago