Is it possible to create a Cmdlet with different functionalities - powershell

I try to find out, if it is possible to implement for example 3 different
functionalities within one Cmdlet.
For example: I use one Cmdlet that can change the Windows Desktop Picture, ADD a Shortcut to the Windows Desktop or remove one or more files from somewhere.
Depending on my use of this Cmdlet and my input.
The goal is to only have one command with different possibilities to use for.
I tried of course a search engine and I searched here. But also, I am not really sure what Im searching for other than my summarize title.
In Microsoft Dokumentation and in this Forum it is written, a cmdlet is for a single function. But when I can convert C# Code into a Cmdlet, then why is it not possible to choose between different functionalities within one Cmdlet?
I would be very happy to receive an answer. Thank you very much.

Related

Obfuscating a PowerShell script

I have written a PowerShell script in many hours and days and would like to obfuscate it, but so that the code is no longer readable or decompilable, but the script can still be executed. Is there something like that?
With regards to actually obfuscating an entire powershell script, this site seems to do just that.
I tested a script a little over a year ago and here are some of my findings:
Windows10: The obfuscated script worked on Windows 10. I dont
remember the Powershell version I had back then.
macOS: Confirmed it also works on Macs (if you have powershell installed), but I remember there were some errors spat out.
I just tested another script a few minutes ago on a Windows Server 2016 (PSVersion:5.1./Desktop) system. No issues so far.
Now, as was already mentioned by previous posters, it is important to note that any obfuscation can be hacked into. It's just a matter of incentive for the hacker.
I say "any" specifically because you dont control the hosts on which your powershell script will be used. And as such, those who do, if inclined, can alter the binary of the powershell program to get it to spit out everything that it does. How easy that is, I do not know. But a quick google search suggests there are settings available that, if turned on, can log the entire execution of your powershell script, obfuscated or not.
A couple of links that touches on Powershell logging:
PowerShell Logging: Recording and Auditing all Things
About Logging Windows - PowerShell - Microsoft Docs
There is a thing named Powershell Constrained language.
Quoting from here: https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode/
Constrained language mode is a language mode of PowerShell designed to support day-to-day administrative tasks, yet restrict access to sensitive language elements that can be used to invoke arbitrary Windows APIs.
In Constrained mode, these are not supported:
COM objects
Unapproved .NET types
XAML based workflows
PowerShell classes
It's best for running administrative tasks, still it's not better for daily uses. To start it use:
$ExecutionContext.SessionState.LanguageMode = 'ConstrainedLanguage'
Read more here: https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode/
The Invoke-Obsufcation wrote by Daniel Bohmann is much better for this purpose. Link: https://github.com/danielbohannon/Invoke-Obfuscation
Usage Guide: https://blog.vonhewitt.com/2017/08/obfuscating-powershell-commands-using/
If you want something to obfuscate your powershell code to make it unreadable but keep it working you should check a project called Invoke-Obfuscationation done by Daniel Bohannan. You should check his talk about powershell obfuscation where he presented the tool.

Programmatically modify PS shortcut layout

I have successfully modified the common attributes of a a shortcut using Powershell; things like changing the icon, setting it to run elevated, etc.
But, in the case of a shortcut to PowerShell itself, that passes a script as an argument, there are some more attributes in the Layout tab of properties, and I would like to be able to modify those attributes as well.
But I can't seem to find any reference to how to get at them.
FWIW, I have been using PS to do this programmatically like this, but I find it problematic when used across different OSs and different versions of PowerShell. So, looking at alternatives.

Explanation of PowerShell for IIS?

I was needing to create a PowerShell script relating to IIS processes and I am new to PowerShell. I have looked at a lot of examples online and kind of get the gist of it, but I just wanted to know, how are we supposed to know all the syntax of the fields in IIS?
Such as for example I see $ApplicationPoolStatus, $ApplicationPoolName, $StartedPools, $StoppedPools, etc a lot in the scripts.
Are we just supposed to know these, or is there somewhere we can find these fields at?
Hopefully this question made sense, thanks!
I am not familiar with IIS and how it relates to Powershell. However, having a $ in front of a name usually indicates a variable. Without being able to see a script that uses the above variable names it would be hard to say exactly what they are, and what they are doing.
Here is a link to several of the IIS Powershell Cmdlets Technet ISS Powershell Cmdlets

How to fill textboxes on a website with MATLAB

I'm trying to use MATLAB to fill in textboxes on a webpage in Internet Explorer without typing directly into the URL. Can anyone explain to me how to do this? I'm pretty lost. I really appreciate any help you can give me.
Thanks!
While I have seen this done before (i.e. running a MATLAB script that automatically fills in fields in Internet Explorer), to the best of my knowledge, I do not believe that there is an actual MATLAB command to directly interface with IE.
Instead, you can make use of the MATLAB command system to call an external program that actually does the interfacing with IE.
For example, you might be able to make a Visual Basic program that interfaces with IE through the InternetExplorer object. I'm not too familiar with VB, but this doc might help. Once you've created this program, use MATLAB's system command to execute it (passing command-line arguments to define what/how to fill in the textboxes).
Take a look at the doc for system for more info.
I've done it many times with a small program called Autohotkey.
With this program you can write a script, that will move the mouse / click the keyboard. you can pass string arguments and use it inside the script. once done, you can call this script from matlab.

"How to Read an SDK" Update for PowerShell?

This is going to sound like a dumb question, but I was wondering where I could find the "Help" file on how to read PowerShell's Help files. To illustrate, when I was first learning VBS, I came across this Sesame Script article on "How to Read an SDK". This was written when VBS was the prominent scripting language for system administration in a Windows environment, so there's no PowerShell examples. I figured there would be a PowerShell equivalent by now, so I've been searching the MSDN/TechNet Library for the past couple weeks and haven't found anything. I've read the Windows PowerShell Owner's Manual, but there was nothing on this specific topic in it nor any resources to which I should go to. So, has anyone found it? Does an update or equivalent even exist within Microsoft's official documentation?
Another reason I ask is because I found a video that helped me accurately read the Help information that comes from the "Get-Help" cmdlet; there's nothing wrong with it, I like the video, but I was wondering where the helpful gentleman, or anybody else, could find the information? It must exist, since he made a video about it, right?
The Windows PowerShell User's Guide has many sub-pages about how to use PowerShell. Use the navigation tree at the left to browse the different topics.
This page in particular talks about how to get help for CmdLets and other topics.
To directly answer the question, the command you can use is this:
Get-Help About_Command_Syntax