Posts

Showing posts from February, 2016

Get a list of printer queues from Active Directory

Image
I was helping colleague earlier this week to clean up the printer queues in the Active Directory. Well, the challenges comes to get a meaningful list of printer queues. Sure you can use the GUI to search in ADUC but that's doesn't give you much details to work with. If you have Windows 8 or Server 2012 and above, then the Get-Printer PowerShell comlet is the best bet. But, what about if I don't have them in production? Try this one liner that fetchs all the print queues from your active directory and save them in to the $printer variable. Get-ADObject -LDAPFilter '(ObjectClass=PrintQueue)' -Properties * -OV printer The AD object is very rich with properties that can be filtered and reported on. It will help your filtering much easier.

Script: Auto-install OMI and PowerShell DSC on CentOS7 Linux

While following the lab instruction for the DSC on Linux, I found the procedure outdated and not fully applicable to the latest build of PowerShell DSC for Linux. (I used CentOS7 in the lab) With the helpful resources on the internet, I was able to piece together a script that works with the current version. (OMI 1.0.8-4 and PowerShell DSC for Linux 1.1.1) The bash script assumes you have the  omi-1.0.8.4.packages.tar.gz downloaded and saved to the same location as the script. It also worth noting following changes: OMI now availalbe as rpm and deb packages.  Linux Development Tool does not seem to be required   OMI daemon is now named: omid wget doesn't work with OMI's website. Manual download is required. If you happen to know how to make wget work with OMI's site, please kindly share it. It's going to make the process much smoother. :-) Reference: https://collaboration.opengroup.org/omi/documents.php?action=view&gdid=34607 https://github.

A case with psEdit

Image
While using the very cool  PowerShell Gallery MVA module  provided by Jeffery Snover to learn about the DSC, I was interested in how the magic was done and took a further look into the module. One command used in there was psEdit  for opening up the script files in the PowerShell ISE. The command could be documented better and Mike F Robbins has a great blog post about its usage. If you run the command without any parameter and press enter without providing anything at the prompt, ISE will open what ever file is in the current directory. Have a look of the screenshot below. Interesting. I then tried to see what psEdit really is with following command: With the command, we can see what the psEdit function is doing: The function wants a mandatory input and then it will iterate through the files in that location and open them in the ISE. The problem comes when you don't pass anything via the variable and not specifying while prompted, the $filenames variable is the

A few random things about Win10, .Net 3.5 and PowerShell

Image
One day in the past week, my colleague and I were trying to get .Net Framework 3.5 installed on Windows 10 test machines. It was required for several applications. (Exactly what we wanted to find out from the test.) Interesting enough, the .Net 3.5 is now a "Feature on Demand v2" item in windows 10. That means the "feature" is by default not part of the image but would be loaded via Windows Update (not WSUS). My colleague suggested using the dism command to complete the install and it worked fine. I thought to myself, how is that going to be done the PowerShell way? So the exploration began. I started  Get-WindowsFeature that I used often on servers. But on Windows 10 I got the red stuffs. Turns out the Get-WindowsFeature cmdlet is part of the ServerManager module which is not included in the Windows 10. (Doh!) Thanks to the intellisense pointed out there's another cmdlet that may or may not help: Get-WindowsOptionalFeature . With further checki

PowerShell tip: Using the -OutVariable

Image
It is very often that I want to run a cmdlet to do something. For example, Get-Process to check the current running process. Cool, I have a list of the running process. So how about saving it to a variable so we can capture and maybe use it later? Sure then we can do the: $p = Get-Process. This is fine when the cmdlet takes a short time to complete and PowerShell does not show you anything until you put the variable back in. In our case $p or $p | Out-Default Say you write an advanced function that scans the remote file system. The process could take a couple cups of coffee before before returning some results. Or you just want to see the results as it moves. Easy! Just add the common parameter: -OutVariable VariableName  (no $ in front of the variable name). PowerShell will display and store the output object at the same time. Meaning you can see the progress on the fly and use the result later. For example: Get-Process -OutVariable p It's a simple trick that wil