Click here to Skip to main content
15,434,647 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Wordle 378 Pin
OriginalGriff1-Jul-22 20:19
mveOriginalGriff1-Jul-22 20:19 
GeneralRe: Wordle 378 Pin
ChandraRam1-Jul-22 20:40
MemberChandraRam1-Jul-22 20:40 
GeneralRe: Wordle 378 Pin
pkfox1-Jul-22 21:57
professionalpkfox1-Jul-22 21:57 
GeneralRe: Wordle 378 Pin
Greg Utas2-Jul-22 0:42
mveGreg Utas2-Jul-22 0:42 
GeneralRe: Wordle 378 Pin
Cp-Coder2-Jul-22 4:21
MemberCp-Coder2-Jul-22 4:21 
GeneralRe: Wordle 378 Pin
Vivi Chellappa2-Jul-22 7:47
professionalVivi Chellappa2-Jul-22 7:47 
GeneralRe: Wordle 378 Pin
jmaida2-Jul-22 11:37
Memberjmaida2-Jul-22 11:37 
GeneralPowerShell AND C# Pin
MSBassSinger1-Jul-22 11:16
professionalMSBassSinger1-Jul-22 11:16 
I am starting to learn PowerShell. I have avoided it for years, because whatever I needed to do beyond a simple BAT file, I could do in C#.

However, I am in a situation where I have to use PowerShell, so I am learning it.

One of the things I learned is that within a PowerShell script, you can call .cs files to run C# code. So this question came to mind, and I thought you all might have some opinions. I wrote a PS script that calls a .cs file and does exactly what I described. I have not mastered calling non-GAC .NET library DLLs yet, but I am working on it.

Why not use PowerShell as a management script, and write C# code to execute the "business logic"? I am not convinced that it is better to use PowerShell cmdlets to hack up some brittle script to do what can be more easily done in C#, which is far more capable and wider-ranging than PowerShell script.

This is a snippet from my script:
PowerShell
## Load the C# code file
## Namespace PSTest  
## Class SomeCSClass
$Source = Get-Content "SomeCSClass.cs" -Raw

## Add the class(es) from the C# code to use
Add-Type -TypeDefinition $Source

## Instantiate the object(s) 
$TestDLL = New-Object PSTest.SomeCSClass

## Build the path for test files (non-static method)
$TestFilePath = $TestDLL.GetCurrentDirectory() + "\PowerShell Example Files\"

## Get a list of files using C# code from a static method
$Files = [PSTest.SomeCSClass]::GetListOfFiles($TestFilePath, "*.txt", 0)


Your thoughts?
GeneralRe: PowerShell AND C# Pin
PIEBALDconsult1-Jul-22 11:33
professionalPIEBALDconsult1-Jul-22 11:33 
GeneralRe: PowerShell AND C# Pin
Richard Andrew x641-Jul-22 12:29
professionalRichard Andrew x641-Jul-22 12:29 
GeneralRe: PowerShell AND C# Pin
jmaida1-Jul-22 14:47
Memberjmaida1-Jul-22 14:47 
GeneralRe: PowerShell AND C# Pin
MSBassSinger2-Jul-22 3:38
professionalMSBassSinger2-Jul-22 3:38 
GeneralRe: PowerShell AND C# Pin
RickZeeland1-Jul-22 21:26
mveRickZeeland1-Jul-22 21:26 
GeneralRe: PowerShell AND C# Pin
MSBassSinger2-Jul-22 3:41
professionalMSBassSinger2-Jul-22 3:41 
GeneralRe: PowerShell AND C# Pin
dandy722-Jul-22 2:57
Memberdandy722-Jul-22 2:57 
GeneralRe: PowerShell AND C# Pin
MSBassSinger2-Jul-22 3:34
professionalMSBassSinger2-Jul-22 3:34 
GeneralRe: PowerShell AND C# Pin
dandy724-Jul-22 11:01
Memberdandy724-Jul-22 11:01 
GeneralRe: PowerShell AND C# Pin
Member 91670573-Jul-22 20:11
MemberMember 91670573-Jul-22 20:11 
GeneralRe: PowerShell AND C# Pin
MSBassSinger4-Jul-22 6:49
professionalMSBassSinger4-Jul-22 6:49 
GeneralRe: PowerShell AND C# Pin
Kate-X2574-Jul-22 2:38
MemberKate-X2574-Jul-22 2:38 
GeneralRe: PowerShell AND C# Pin
Southmountain4-Jul-22 5:13
MemberSouthmountain4-Jul-22 5:13 
GeneralRe: PowerShell AND C# Pin
MSBassSinger4-Jul-22 6:50
professionalMSBassSinger4-Jul-22 6:50 
GeneralRe: PowerShell AND C# Pin
Kate-X25711-Jul-22 0:32
MemberKate-X25711-Jul-22 0:32 
GeneralRe: PowerShell AND C# Pin
NiL^4-Jul-22 5:29
MemberNiL^4-Jul-22 5:29 
GeneralRe: PowerShell AND C# Pin
rnbergren4-Jul-22 5:46
Memberrnbergren4-Jul-22 5:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

Who do you listen to most when making decisions about software development?
  Results   467 votes