Reputation: 32635
I just got a project where I have to do the following on a Windows OS:
I'm an experienced C\C++ programmer, but I thought this would be a perfect time for me to start learning about scripting.
Candidates that I thought of are: ( Python || Ruby ) && PowerShell.
Are those the kinds of things I can accomplish with, say, IronPython+Powershell? Or are there better tools/languages out there?
PS: Is PowerShell meant to replace VBScript? Also, what is VB.net good for anyway now that C#, WPF, and Powershell exist?
Upvotes: 0
Views: 520
Reputation: 354566
Except for the seventh item on your list this should be fairly trivial using Powershell and WMI, as this is perhaps the natural domain for Powershell. Since you won't need another language for the first six list items it shouldn't really matter what you use for the last one. You probably can use PS (I've never done IO with it, though) or whatever suits you.
As for your second question: VBScript is probably not going to go away in the near future as the Windows Script Host is still a safer bet when writing small scripts for deployment, as it comes preinstalled on every Windows since 98. Powershell is only included in Windows 7 and later. That being said, Powershell is surely targeted at obsoleting WSH and CMD for automation purposes since it offers the same features of the aforementioned ones and much more (like easy .NET and WMI access).
VB.NET on the other hand is one of the primary .NET languages marketed by Microsoft. It has little to no relation to VBScript, is no competitor to Powershell or WPF (heck, those are completely different technologies). You may see some convergence with C# going on as both languages still seem to struggle a little finding their intended market. Still, VB.NET is the easiest choice of switching to .NET when you're a VB programmer and there were/are lots of them MS didn't want to lose just because they created .NET.
Upvotes: 8
Reputation: 1004
I think PowerShell is ideal for this task because it is optimized for this sort of system information retrieval. WMI is exceptionally easy to use from PowerShell as opposed to C# IMO (and I'm a C# dev by day). Heck, let's see how easy this is from PowerShell:
#1,2, 3 and 4
PS> Get-WmiObject Win32_LogicalDisk |
>> Format-Table Name, VolumeName, FileSystem, Size, FreeSpace -auto
Name VolumeName FileSystem Size FreeSpace
---- ---------- ---------- ---- ---------
C: NTFS 160038907904 100353536000
D:
E:
F: PDC2008 NTFS 160039239680 40155922432
V: Vista NTFS 250056704000 33944559616
#5
PS> dir <path> -r | where {!$_.PSIsContainer} | Measure-Object
#6
PS> dir <path> -r | where {!$_.PSIsContainer} |
>> Format-Table Fullname, Length -auto
And PowerShell can handle #7 easily via its ability to use the .NET Framework. For an example of fseek style programming in PowerShell check out this tail-content script starting around line 139.
Upvotes: 4
Reputation: 19117
Powershell was designed as an automation platform for Windows. So sure, Ruby, Python, Perl, VBScript etc can do the job, why not choose the tool best for the job. Here's how to get some basic drive info:
$drives = Get-WmiObject -Class Win32_LogicalDisk | ? {$_.DriveType -eq 3 }
$drives | select DeviceId,VolumeName,FileSystem,FreeSpace, Size
Number of files in a directory
Get-ChildItem c:\path -Recurse | Measure-Object
Get-ChildItem c:\path | Measure-Object
With info on file size
Get-ChildItem c:\path -Recurse | Measure-Object -Average -Sum
-Maximum -Property Length
And for file processing, you can use native cmdlets such as get-content or invoke and instantiate .Net types.
Upvotes: 1
Reputation: 907
As for Perl, Ruby too has access to all Win32 API and WMI functions.
Upvotes: 0
Reputation: 3820
I'll give you the unpopular answer then since no one else has added it: Perl.
If you're comfortable with the Win32 API as a C/C++ programmer, Perl may be the easier way to go. It has modules for accessing the Win32 API and Perl is quite easy for C/C++ programmers to get up to speed in. Perl has always done the job for me in the past.
Upvotes: 0
Reputation: 20189
PowerShell can easily handle 1-6. Number 7 can probably be done in PowerShell, but there may be better options depending on the details.
See What tutorial do you recommend for learning PowerShell? for some good info on learning PowerShell.
Upvotes: 6
Reputation: 483
You can do that in either IronPython|IronRuby or Powershell. I'd recommend IronPython since it's a real language (older than C# or even Java), with lots of support and full access to the .NET APIs you will need (or even COM APIs).
I'd suggest you to read this article that answers your exact question: http://pythonconquerstheuniverse.blogspot.com/2009/04/ironpython-windows-scripting-language.html
Upvotes: 4