As of the KB3000850 update and PowerShell 5.0, PowerShell has included script block logging so that admins would have more tools for the blue team side of pen testing. If you’re unfamiliar or have never heard of it before, I recommend giving this blog post a read. Not only does the post describe what script […]
Tag: function
PrimalForms 2009: OnApplicationLoad Function
Recently on the forums we had a user who wanted to know why he couldn’t initialize the form controls within the OnApplicationLoad function. Seeing how this can result in some confusion, we would like to elaborate on the subject. The purpose of OnApplicationLoad is to initialize any dependencies necessary for your form script to run, […]
Out-CSV Revised
A while ago I published a short function to create CSV strings. While working on another task I came across $OFS, which is something I know about but never really think about. $OFS is an intrinsic PowerShell variable that controls the output field separator for arrays. You can modify this variable which made me realize there was a better way to handle my Out-CSV function. Here’s the revised function.
Out-CSV
Sometimes it’s the little things that can make life easier. Here’s one of them. We know that PowerShell treats comma separated items as an array:
PS C:\> $a=”a”,1,”b”,”jeff”,4
PS C:\> $a
a
1
b
jeff
4
PS C:\>
But what if you want back in its original comma delimited list? Or suppose you wanted to create a comma delimited line of all running services? Export-CSV isn’t really going to help in these situations. I came up with function called Out-CSV.
Get ServiceAccount Name with ADSI
One drawback to the service objects returned from Get-Service is that you can’t see what account the service is running under, often referred to as the service account. This will be something like LocalService or perhaps even a special user account like Mydomain\svcAccount123. You can retrieve this information by querying Windows Management Instrumentation (WMI) and the Win32_Service class. But did you know you can also use ADSI?
PowerShell Tree
Of course since I’ve posted a VBScript version of the Tree command, I had to do it in PowerShell. On one hand, this would have been pretty straightforward since PowerShell can use COM objects and I could have simply reused the FileSystemObject. But that didn’t feel right. So I came up with a version that uses cmdlets and PowerShell features like the -f formatting operator. So here is TREE.PS1.
Get Network Connections
I love that part of my job is helping people out in the forums as ScriptingAnswers.com. A recent post asked about finding out what network drives were mapped on a remote computer using PowerShell. The task sounded familiar so I poked around my script pile and found an old VBScript that used WMI and the Win32_NetworkConnection class. Great. Get-WMIObject to the rescue:
Get-WMIObject win32_networkconnection -computername Desk23
You even get a nicely formatted summary. But you me, I can’t resist tinkering so I wrote a function that enhances this basic command I call Get-NetConnection
Show-CSpace
My latest Prof. PowerShell column has a function that takes a computername as pipelined input. It then returns a custom object showing free space on drive C:\. The point of the column was to demonstrate how to make a function behave like a cmdlet and take pipelined input so it’s not necessarily the most glamorous function I’ve ever written.
Anyway, the function got mangled in formatting for the web. This is what it should be…
Are you leading me on?
Recently in the VBScript forum at ScriptingAnswers.com there was a question about creating a file name from the current date, but with leading zeros. This is a pretty common question. It is easy enough to get the month or day portion of the current day.
dy=Day(Now)
However there is no VBScript function to format this to provide a leading 0. Neither FormatDate or FormatNumber can help. So instead I offered a function. Here is a modified version of what I originally offered that is a little more flexible.
Get TweeterTagged User
If you use Twitter and like to script, especially in PowerShell, then I think you’ll like this. A new site, TweeterTags.com has launched that allows you to tag your Twitter profile. The upshot is that this makes it easier to discover like-minded individuals. So let’s say I want to find all the PowerShell tagged users, here’s how I can do it directly from PowerShell with a simple script.