Posts Tagged ‘function’

PrimalForms 2009: OnApplicationLoad Function

Wednesday, January 6th, 2010 by David Corrales
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…   More »

Out-CSV Revised

Friday, May 15th, 2009 by Jeffery Hicks
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.   More »

Out-CSV

Thursday, April 2nd, 2009 by Jeffery Hicks
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.   More »

Get ServiceAccount Name with ADSI

Tuesday, March 31st, 2009 by Jeffery Hicks
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?   More »

PowerShell Tree

Wednesday, March 25th, 2009 by Jeffery Hicks
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.   More »

Get Network Connections

Thursday, March 19th, 2009 by Jeffery Hicks
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   More »

Show-CSpace

Monday, March 16th, 2009 by Jeffery Hicks
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...   More »

Are you leading me on?

Friday, February 6th, 2009 by Jeffery Hicks
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.   More »


Entries (RSS) and Comments (RSS).