I mentioned before, Powershell is a great tool for IT/SysAdmins, for Cloud Engineers (Service Engineers, SRE etc…) and in my opinion even developers, if used to the full extent of its capabilities. Everyone can find their own dimension using Powershell: you can fire up the shell and type away commands and one-liners, or write quick scripts ready to go next time around, or you can transform those scripts into Advanced Functions and combine them into Modules for reuse and distribution among your colleagues and maybe share online. All these different uses allow (I think almost call for) different writing styles: if I’m at the interactive console (other languages would call it REPL) I use all sort of shortcuts and aliases to save time and typing. For example let’s take one of the commands I used in Length, Count and arrays: At the console I would instead use: Here’s the breakdown: “dir” is an alias for Get-ChildItem “-di” is a contraction for “-Directory” (I want to list only folders, not files) “?” is again an alias for Where-Object “-m” is a contraction for -Match “select” is an alias for Select-Object “-exp” is a contraction for -ExpandProperty You can get a list…
-
-
Length, Count and arrays
Powershell was born with ease of use in mind, it has a fairly flexible syntax and is good at guessing the user’s intention. For example the Addition operator can deal with math if the passed values are numbers: PS >_ $a = 1PS >_ $b = 2PS >_ $a + $b3 It can also properly concatenate strings if the passed values are of that type: PS >_ $a = 'sample_'PS >_ $b = 'string'PS >_ $a + $bsample_string When used interactively at the console, Powershell tries to print a nice textual data representation with tables, lists and so on. For the sake of this discussion let’s assume we want to filter a list of folders: PS >_ Get-ChildItem -Directory Directory: C:\varCount Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 4/8/2019 1:23 PM Microsoft.ADHybridHealthService d----- 4/8/2019 1:23 PM Microsoft.Advisor d----- 4/8/2019 1:23 PM Microsoft.AlertsManagement d----- 4/8/2019 1:23 PM Microsoft.Authorization d----- 4/8/2019 1:23 PM Microsoft.Automation d----- 4/8/2019 1:23 PM Microsoft.Billing d----- 4/8/2019 1:23 PM Microsoft.Cache d----- 4/8/2019 1:23 PM Microsoft.ClassicCompute d----- 4/8/2019 1:23 PM Microsoft.ClassicNetwork d----- 4/8/2019 1:23 PM Microsoft.ClassicStorage d----- 4/8/2019 1:23 PM Microsoft.ClassicSubscription d----- 4/8/2019 1:23 PM Microsoft.Commerce d----- 4/8/2019 1:23 PM Microsoft.Compute d----- 4/8/2019 1:23 PM Microsoft.Consumption d-----…
-
Get any Function’s source code from the Function PSDrive
You may be already familiar with the concept of PSDrive or Powershell Providers: PowerShell providers are Microsoft .NET Framework-based programs that make the data in a specialized data store available in PowerShell so that you can view and manage it.The data that a provider exposes appears in a drive, and you access the data in a path like you would on a hard disk drive. You can use any of the built-in cmdlets that the provider supports to manage the data in the provider drive. And, you can use custom cmdlets that are designed especially for the data.The providers can also add dynamic parameters to the built-in cmdlets. These are parameters that are available only when you use the cmdlet with the provider data. You are likely using some Providers (especially the File System Provider) without even realizing it, while some come in handy if you need to perform actions on specific types of objects. For example you can list the certificates under your profile running Get-ChildItem -Path Cert:\CurrentUser\My. Notice the use of “Cert:” (Certificate) Provider (or PSDrive). The Function: drive allows to list all functions available in the current powershell session: As you can see some functions come with…