Calling the Command Line in C# - Scripts, PowerShell, Automation, and more

  Рет қаралды 34,643

IAmTimCorey

IAmTimCorey

Күн бұрын

The command line is an incredibly powerful tool to take advantage of in development. When you know how to use the command line, you can automate just about anything. This is why tools like Git, Docker, and even .NET are command-line first products. In this video, we are going to see how to build C# applications that can call command line applications directly.
github.com/Tyr...
Full Training Courses: IAmTimCorey.com
Source Code: leadmagnets.ap...
Mailing List: signup.iamtimc...

Пікірлер: 95
@BooBar2521
@BooBar2521 Жыл бұрын
Dude, thank you for sharing this. You explain so well what possibilities I gain using this with easy examples. This was exactly what I was searching for!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@jricardobaptista
@jricardobaptista Жыл бұрын
Congratulations, you've created the best C# youtube channel ever. I love all the contents, your channel have the most complete content...
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thank you!
@delw1138
@delw1138 2 жыл бұрын
Thanks for showing the CliWrap library, didn't know it was out there. I have made many CLI apps for WSUS server automation, automated summary reports for backups and other administrative function automation.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@Rhodair
@Rhodair 2 жыл бұрын
this looks like such an awesome way of creating personal command scripts and cron jobs I'd messed with bash and started getting into Python once I saw there was a typing library, but C# is definitely my preferred wasn't aware of CliWrap until now, but this instantly has me excited to automate more
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Awesome!
@dilipjain9581
@dilipjain9581 2 жыл бұрын
Thank you for keeping updated with Microsoft technologies! I have bought 5 courses from your site, and one of them was Getting Started with Azure. I would like to learn more Azure Cloud services in depth and would love if you keep updating existing course content of Azure. I am much interested in Azure Advance course.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
While I won't just be adding new content to that course, I will be adding more courses that cover other cloud services. There are so many out there that I won't be able to cover them all, but as people express a need for certain services, I'll try to get them covered. You can find out what people are asking for (and ask for some of your own) at suggestions.iamtimcorey.com
@dilipjain9581
@dilipjain9581 2 жыл бұрын
@@IAmTimCorey I just suggested there. Thanks for the awesome contents and courses. I would like to understand and study Azure Kubernates with Microservice architecture (Docker) in depth knowledge on Azure Cloud course. If you create a course for it, I will be the one who will buy first for 100% sure. Many many thanks in advance for it.
@waynehawkins654
@waynehawkins654 2 жыл бұрын
Nice Tim. As someone that wear two hats, Network Manager and Software Developer, this is going to allow me to developed tools to manage many things on our Servers. Maybe running as a Services program. Thank you so much.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Awesome! I am glad it was so helpful.
@marvelcz8974
@marvelcz8974 2 жыл бұрын
Well ... all that is missing now is video about Uno Platform and then all my target tech stack is here on this channel. Well done Tim.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Uno is on my list of topics to cover. That's a great system.
@swedishprogrammer
@swedishprogrammer 2 жыл бұрын
Thanks for sharing C# content! 😇
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@alexdpaiva83
@alexdpaiva83 2 жыл бұрын
Thanks for the tip from Brazil 👏🏻👏🏻
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@anthonysteinerv
@anthonysteinerv 2 жыл бұрын
No way, I didn't know that Nuget package, like a month ago or something like that I was kind of trying to do all of this with Process library, and I managed to do it, but holy shit it's a lot easier with this. Thanks for this, now there's nothing I would use python for, unless this doesn't work as good with WSL/Linux.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I am glad it was so helpful.
@pasdilhan
@pasdilhan 2 жыл бұрын
Great! useful stuff.. Thanks for sharing Tim
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@user-xt8dx8zo8i
@user-xt8dx8zo8i Жыл бұрын
As always Tim Loved you video !!!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thanks!
@ajvenable7937
@ajvenable7937 2 жыл бұрын
Great stuff Tim. Thanks!
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@ajaysingh9001
@ajaysingh9001 Жыл бұрын
Hi Tem, Greate stuff, I am trying to use this but stuck on Passing Read-Host Input parameter for Powershell script
@parsagachkar3140
@parsagachkar3140 17 күн бұрын
this is actually cool, but I was wondering if I could monitor a process that I've started! like starting an AVD and waiting for when it's ready (a specific message to be printed in stdout) then fire-up Appium to control it! this would ease my CI pipelines for my mobile apps a lot!
@noelfrancisco5778
@noelfrancisco5778 2 жыл бұрын
This is an awesome tool, thank you for sharing :)
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@xarioln
@xarioln 2 жыл бұрын
definitely a missed naming opportunity :/ ... Cling wrap!
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
lol
@harshitgoel566
@harshitgoel566 Жыл бұрын
How to run scripts requiring Administrator access in power Shell from C# code
@bluehippotech
@bluehippotech 2 жыл бұрын
For powershell specifically you can also use the powershell sdk and system.management.automation and subscribe to multiple streams
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks for sharing.
@mjuniorjr5942
@mjuniorjr5942 2 жыл бұрын
Hi, Tim! I was trying to make this question in your question website, but it has more than 500 chars. Can you explain me or make a video about it? The question: Let's suppose that we have two libraries, let's call them x and y. These two are dependent on a third library, named z. Library x depends on a version of library z. The y library depends on a different version of the same z. These verses are incompatible. How does .net manage this? Does the concept of dlls make this possible? the assemblies(dlls) is similar to containers concept? In a dll do you have a .net running? if yes, why don't the .net standard 2 and 2.1 libraries talk to each other, if they will run their own dotnet machines, for example? If I create library in dotnet 5 version, it can be called into a dotnet 6 app? And If I create a dotnet 6 library, it can be called by a dotnet 5 app? Thanks!
@eduardofelippetto
@eduardofelippetto Жыл бұрын
Hey Tim, this is a great video. However, I cannot make it work with 'dotnet ef dbcontext scaffold' or 'Scaffold-DbContext''. I would like to make the DB First scaffolding process triggered from a Console App. Could you please help? Thank you so much!
@donnyjames2304
@donnyjames2304 2 жыл бұрын
question...can this package be used to call excel macros?
@niravdaraniya7792
@niravdaraniya7792 Жыл бұрын
Thank you Question : can we use "Cliwrap" inside the docker container ? means I have .Net core application and which uses "Cliwrap" next i have created docker images of this .Net core application and then run this docker image on linux machine. is it possible ?, I have tried this but its throwing error.
@mikebreeden6071
@mikebreeden6071 2 жыл бұрын
Wow! I got to about 14:30 when I thought... "I know what I could do with that". My monitoring applications could have really use that. I can think of all kinds of uses. ... Sure, open my eyes, but that's what you do, isn't it. ... Perhaps a funny thing... I've been interviewing some lately and I keep getting asked questions about ASP.Net details like stuff in the Request pipeline. Well, I don't remember. That was 6 months ago I experimented with .Net 6. I've gone on to other things like architectural possibilities like this. I did .Net 6. That was then and my focus has moved on. Now I'm doing something like this or DynamoDb in my Lambda website, but they will never know that
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I'm glad it will be helpful.
@jacekbialek409
@jacekbialek409 Жыл бұрын
Hi Tim, great video. Is it possible to use the same tool inside docker ?, and call scripts from host ?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Yes, it is.
@FellTheSky
@FellTheSky Жыл бұрын
is it possible to execute a c# script inside a .bat file and get a return? I've managed to do the first part, but failed in getting the return out of the c# script to the .bat code
@IAmTimCorey
@IAmTimCorey Жыл бұрын
By C# script, I am assuming you mean a C# application (like a console application). Yes, it can return a value, but more commonly the Console.WriteLine is the output.
@h.kargar71
@h.kargar71 2 жыл бұрын
very nice
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@intelligentcoding689
@intelligentcoding689 Жыл бұрын
hi, Thanks for the amazing videos. I have a problem to place auto-installation of SqlLocalDB into the MSIX package, or something like online installation while installing my Application from MS-Store. I'm using .NET CORE 3.1 and want to run a simple SQL-Database from storage (like D:\Documents\myApp\myDatabase). it's working on my machine, but the users may have not SqlLocalDB installed on their own. would you please help me.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
That’s a tricky one to solve because MSIX is designed to be self-contained so installing it in your own isn’t feasible. You might want to look at using SQLite instead.
@Rajeshsingh-ws5th
@Rajeshsingh-ws5th 2 жыл бұрын
Thanks Tim for wonderful stuff, keep posting and helping. One question but not related to this post. Is minimal api (c#) is same as node.js restapi kind of pattern?
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
That's a mix of a few different things. An API in C# (whether minimal or not) is like a Node.js API. Both of them can implement REST, although the actual REST spec is not something that anyone actually fully implements.
@ashutoshpattnaik5446
@ashutoshpattnaik5446 2 жыл бұрын
Hell Yeah. This is the video.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thank you!
@demariners
@demariners Жыл бұрын
Thank you for this! Helps a lot. One question though. I am trying to run something that requires Admin priv. Is there a way to to do it with this library?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I looked into this a while ago. I believe the best solution is to run your calling app as administrator. Test that and see if it works.
@Steaky1300
@Steaky1300 6 ай бұрын
You could always use an app.manifest file.
@pxnchx93
@pxnchx93 2 жыл бұрын
How does this Cliwrap library stack up against just simply using the System.Diagnostics.Process class?
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
It is an abstraction layer on top that adds a lot of great features.
@andywalter7426
@andywalter7426 2 жыл бұрын
One question I have is I tried the git command even using cmd and says does not recognize the command. How does somebody fix that issue. Seems like a bug in the cmd because git is obviously supposed to be recognized.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
It isn't a bug, it is how your machine is set up. First, you need to make sure git is installed. Second, you need to check your PATH variable to be sure git is added to it. In Windows, you cannot just call whatever you want wherever you want. You need to navigate to the folder where the EXE is located to run it (or call it by its full path). The way around this is to put that EXE's file location on the PATH variable. That's what git will do by default when you install it.
@victorcapeluto8663
@victorcapeluto8663 2 жыл бұрын
Hi Tim, this is a great tool that I didn't know it existed, I'm trying to run an async process (bat file) and show what's happening to the user but I'm in a windows forms app, how can I do that? It is a big file though. Thanks
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I don’t have a video on that. Sorry.
@hillarysagwa5064
@hillarysagwa5064 2 жыл бұрын
thank you
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@andywalter7426
@andywalter7426 2 жыл бұрын
Actually you can do command lines in the maui if you decide to only target windows.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Even if that were technically possible, why would you create a MAUI application that could only target Windows? There are much better options for that.
@bootsector13
@bootsector13 2 жыл бұрын
its like a c# inside a c# in a c# code.. multiverse really exist!
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
There you go.
@dreamdancer8212
@dreamdancer8212 2 жыл бұрын
How exactly did you pull up that terminal? Great stuff btw.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
That's the Windows Terminal. I believe you still have to install it yourself on Windows 10 but it comes standard in Windows 11.
@dreamdancer8212
@dreamdancer8212 2 жыл бұрын
Thanks a lot. I will have a try . . . : )
@andywalter7426
@andywalter7426 2 жыл бұрын
One question is why you are using a nuget package when you can do the command stuff without the nuget package. I would have liked to see how the command line stuff would have been done without the nuget package just in case a person does not want to use that nuget package or even create their own stuff.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
We are using the NuGet package because we don't want to reinvent the wheel over and over. The point of development isn't to write code. The point is to accomplish the goal. Almost no one's end goal is to call the command line. That's one of the things they need to do, but their actual goal is beyond that (for example, it might be to automate a process - calling the command line is just the means to that end). If you want to see how to do all of that work on your own, go to the repository and read the code.
@khanfaizan05
@khanfaizan05 2 жыл бұрын
First view.. first comment
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@micro2743
@micro2743 2 жыл бұрын
I honestly can't imagine doing this unless there was no API or any other way of obtaining the same information.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
This isn't something you do every day, but there aren't APIs for a lot of these tasks. They are specifically command line applications, so you need to call them via the command line for automation purposes. This is what all DevOps systems do for CI/CD.
@KoScosss
@KoScosss 2 жыл бұрын
Flashbang warning: 3:21
@AdamsTaiwan
@AdamsTaiwan 2 жыл бұрын
I created my own installer that wraps cmd, powershell and calls management api and can run an internal script. Windows flagged it as a virus.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
That is tricky to get right.
@AdamsTaiwan
@AdamsTaiwan 2 жыл бұрын
@@IAmTimCorey Yes, but not too bad and I only have one .exe for the old .Net Fx.
@mnezon1314
@mnezon1314 2 жыл бұрын
Thanks for the video. Its a nice lib, but their activism in the github repo makes me uneasy, especially since there was a cyber attack on Russian computers with a NodeJS package. I am not pro Russia or Russian myself, but i do not like the way they force you to support their political beliefs to use their software. What about Russian developers who do not support Putin, which is the majority of young people in Russia? Pretty distasteful behavior from the maintainers. I will pass on using this package.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Well, this is where you have to remember that the owner of a package has the right to specify how a package is used. As for the owner "forcing you to support their political beliefs", I don't see that in their statements. What the author (who is Ukranian and who has had their country's civilians and military personnel alike killed by the Russian invaders) is saying is that the invasion by Russia is wrong and that there isn't a "both sides" to one country killing another country's civilians. Let's put this in more personal terms. I imagine you have a family. Imagine if someone came into your house, killed your mom and brother, and was trying to claim your house as theirs while hunting down the rest of your family. Would you be ok with someone saying that action was "political" and that "both sides" have a point? That's the very scenario that the author of this NuGet package is facing. I'm very much not ok with how Russia is acting and I'm very much ok with how Ukrainians feel about it.
@stepbackandthink
@stepbackandthink 2 жыл бұрын
So a lesson in coding just turns out to be an advert for third party software.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I'm going to assume you are new to software development and not just being willfully ignorant. In C#, we use NuGet packages to help make our lives easier. Even .NET is broken out into NuGet packages so that we can add only what we need to build an application. We don't just reinvent the wheel with every project. In this case, a developer created a NuGet package (for free) that extends the System.Diagnostics.Process object in .NET. This package makes it easier to work with Process so that we can more quickly, more efficiently, and more safely talk to command line systems. So, what I just did is show you how to make your development easier and better for free with an open-source library. Where exactly is the problem?
@stepbackandthink
@stepbackandthink 2 жыл бұрын
@@IAmTimCorey I never mentioned a problem.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Saying the video is "an advert for third party software" was the problem. This is a lesson in how to write software in C#. It isn't an advertisement. The implication with your statement is that the video somehow isn't actually teaching you how to write C# but is instead just advertising to you to get someone's software. That's not what is happening.
@stepbackandthink
@stepbackandthink 2 жыл бұрын
@@IAmTimCorey Perhaps that could be reflected in the title then.
@ChristianHaugland74
@ChristianHaugland74 2 жыл бұрын
@@stepbackandthink maybe you could Step Back And Think?
@angelman26
@angelman26 2 жыл бұрын
Hi Tim. I'm new to C# so I appreciate your video and explanations. I have a question that no one has been able to help me with so far. I wrote a PowerShell script with a GUI in Windows PowerShell ISE that works pretty well. I saw some GUIs made with XAML on KZfaq and was immediately interested in learning it and building a GUI with it for the commands in my PowerShell Script. I have searched hi and low and cannot find a single person that can show me how to run my code in C#. I was able to run something simple like this as a test, private void BtnFindComputer_Click(object sender, RoutedEventArgs e) { PowerShell.Create().AddScript("Start-Process Notepad.exe").Invoke(); } But that's not what I'm looking to run. How can I run something like this, private void BtnFindComputer_Click(object sender, RoutedEventArgs e) { Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $textbox1.Clear() $LFilter = $textbox10.Text $Username = Get-ADUser -LDAPFilter "(anr== $LFilter)" -Properties * if ($Null -eq $Username.SamAccountName) {$textbox1.Text = "N\A"} else {$textbox1.Text = $textbox1.Text + ($Username.SamAccountName.ToString()) -replace "(CN=)(.*?),.*",'$2'} } Is this even possible? I can send you any code via email that could be helpful in understanding my goal. Thanks for any help that you can provide and thanks again for the video.
10 C# Libraries To Save You Time And Energy
33:59
IAmTimCorey
Рет қаралды 206 М.
Stop using the Process class for CLI interactions in .NET
15:04
Nick Chapsas
Рет қаралды 51 М.
Oh No! My Doll Fell In The Dirt🤧💩
00:17
ToolTastic
Рет қаралды 3,7 МЛН
WILL IT BURST?
00:31
Natan por Aí
Рет қаралды 20 МЛН
How I Did The SELF BENDING Spoon 😱🥄 #shorts
00:19
Wian
Рет қаралды 36 МЛН
Working with Null in .NET 6 and C# 10
57:26
IAmTimCorey
Рет қаралды 35 М.
7 Essential Command Line Tools (2022)
9:12
Tech Craft
Рет қаралды 209 М.
Creating your first PowerShell module in C# - Emanuel Palm,Justin Grote - PSConfEU 2023
1:32:41
Intro to Records in C# 9 - How To Use Records And When To Use Them
1:19:44
The Only .NET Scheduler You Should Be Using!
16:38
Nick Chapsas
Рет қаралды 49 М.
Stop using the CD Command
9:01
Chris Titus Tech
Рет қаралды 37 М.
Factory Pattern in C# with Dependency Injection
1:07:33
IAmTimCorey
Рет қаралды 106 М.
Dependency Injection in .NET Core (.NET 6)
1:00:32
IAmTimCorey
Рет қаралды 188 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 154 М.