Earlier in August we mentioned that modularity and abstraction are quite helpful. PowerShell modules can help enable these concepts.
You might ask “Modules… why can’t I just write a function?” There are a number of benefits to bundling your functions into modules:
Simplify code organization
Group related functions together
Share state between functions, but not with the user
Re-use “helper functions” that you don’t want exposed to the user
Improve discoverability:
Find-Module MyModuleGet-Command -Module MyModule
* Simplify distribution: Install-Module MyModule
`Where does that last bullet come from?
The PowerShell Gallery
If you’ve worked with Perl, you’ve probably used CPAN, which archives more than 150,000 modules. Other languages have similar tools, like PyPI for Python, or RubyGems for Ruby.
Hello Powershell.org! This is the first time I’ve posted for anyone outside of my own powershell blog site PowerShellMasters.com and I just want to thank PowerShell.org for everything they do for our community. I think most of you would agree that this site is one of the best PowerShell sites out there today and I am grateful for the opportunity to reach so many PowerShell people. OK enough with the touchy-feely stuff. 🙂
Password policies are the best 😀 Sometimes they lead to account logouts when someone forgets to logout of a session somewhere on the network though. It might be the TS session they use once a quarter for reporting or maybe you know the feeling when you RDP to a server only to find that it is locked by 2 other admins who forgot to logoff when they left. (Off cause this never happens… we all use PowerShell…) Anyway, this had me searching for a user session somewhere on the network. The worst thing is when my own password expires. I hate when my account ends up being locked. Therefor I made it a rule to just check all servers before I change password. There are multiple ways to do this but of course I tend to go the PowerShell route.
Often I have had to check something against all servers or clients. A classic problem and every time I run into the it it’s time consuming and running the job multithreaded would be nice.
A few years back I found a nice little script for multithreading which I have been using quite often. Unfortunately this wasn’t a module. And I can’t remember where it came from. So this week I set my mind on recreating this as a module and to see if I can publish it on PowerShell Gallery.
It’s no secret that Microsoft’s WebAdministration module isn’t universally loved. It’s functionality isn’t deep, and it doesn’t play well in the PowerShell pipeline. There are also a number of things in it that run really slowly, making bulk administration a pain.
Last week, Baris Caglar announced that Windows 10 contains a new IISAdministration module, which is a rough draft of what is hoped to be a final module in Windows Server 2016. If you use IIS, get hold of this and start testing so the team can get feedback. Note that this is a _feature of Windows 10; _I haven’t yet been able to test and see if file-copying it to another version of Windows will work or not (if you try, please post your results in a comment). The module seems to rely heavily on the IIS Administration .NET class, going so far as giving you easy access to an instance of it so you can code against it directly for whatever the module itself doesn’t offer.
# Invoke-Sqlcmd2 -ServerInstance SQLServer1 -Database MyDB -Query 'SELECT * FROM Table1' If you aren’t a masochist, the latter probably looks a bit nicer. Oh, and it offers other parameters, error handling, parameterized SQL queries, built in help, and other benefits the .NET code block misses.
Working with wifi I have often needed to do a survey of the surroundings, and therefor I loved that windows 7 (maybe even Vista) introduced more advanced netsh with wifi support.
There’s a lot of useful information but it might be nice to have a more graphical overview. The thing is that a text blob like this is not very handy to work with.
Some time late last year I heard a guy from the powershell team on the Powerscripting podcast talk about ConvertFrom-String and the new template based parsing. And it occurred to me that you can combine this with a simple powershell progress bar (write-progress) to give a visual representation of signal strength.
Are you starting to use version control at work? Are you being pestered by fellow PowerShell aficionados to start learning version control? Did you catch the PowerShell.org Crash Course in Version Control and pick up some Git and GitHub experience? Shameless plug, sorry : )
Version control is just the start. What if we want to automate testing? To deploy our files, folders, and other artifacts out to production or other environments? Version control alone offers some nice benefits, but without these extra steps, it might introduce some pain points!
So if you’re like me and don’t know any other programing/scripting language then all this PowerShell stuff is a bit daunting. So to help, this articles is on
PowerShell Variables. The thing is that Variables in PowerShell are very important. I’m assuming you know what a cmdlet is? The very basic underlying tools that make powershell work. They are like powershell building blocks or bricks in a PowerShell wall. For example, get-aduser gets a list of all the users in AD and includes a few details like SID, name and distinguished name. So that little cmdlet gets all that information, and more once you learn to manipulate it. If cmdlets are the bricks then Variables are the mortar. They hold all this information you have gathered together and let you save and pick and choose what you want.
I’m going to have a PowerShell ramble on a semi regular basis. What prompts me to write here on powershell.org is that I love powershell. I makes my job so much better. I’m an IT Pro and work for a large ish world spanning company. I mostly work with windows servers but get to work with other technology too. Like VMware and Citrix for example. The other thing I want to point out is that I’m not a programer. I don’t know VB Script and no one taught me
PowerShell
. There are many people though that helped me on my PowerShell Journey through their books, blogs, postings, and videos.