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
Related
currently learning how to write scripts for the first time, specifically in powershell. I figured this would be a simple exercise, and I know that get-childitem is a good place to start for this script. Unfortunately, I am having a hard time articulating the things I see online in order to use them myself. Could someone show me how to do this and give me a simple breakdown for it? Thank you tons.
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.
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.
I've written a simple script that has multiple custom functions stored as modules. I have done it this way because I was always been told that if your function can be reused by other things then it should be a module and not a .\ source include. I'm starting to think that mantra isn't right in my current scenario. I am trying to convert the script to an single .exe so that I can install it as a windows service.
Probably should acknowledge that I understand why you wouldn't want to include system modules like Active Directory or IIS management for the obvious issue that could lead to but I'm only trying to include custom functions in a single disputable non editable way.
I have used PowerGUI in the past but can't find any valid exe's for that since DELL have removed it and from memory, I don't think I've ever used it with a module.
I've tried PS2EXE-GUI and PS2EXE. Both of these make the exe and everything works fine while the modules exist. However, as soon as I put the exe on a server that hasn't got the Modules deployed to it, it fails to run. I thought the compile followed all the dependencies and included them as part of the build into the single exe? That appears to not be the case.
I've also tried the PowerShell Studio 2018 by Sapien, but based on their forums you can't include modules into the complied exe. Which again feels wrong if they are actually just custom functions, but it's the way they've written it.
I see https://poshtools.com/docs/posh-pro-tools/merge-script/ would possibly do what I need but that's chargeable and it looks like it actually merges all the content back into a single file. Given the time pressure I'm starting to think I'll have to pay if there are really no other better options. I just don't have time to join everything together manually and I can't help thinking there is a better way I'm missing!
Can anybody please suggest other options?
Could I also get clarification around my original mantra (functions go in modules...)?
"No, never!" or "Yes, always!" or "It's just wrong in this scenario."
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