Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My New Years Resolution - Learn PowerShell 1

Status
Not open for further replies.

dm4ever

Technical User
Jul 3, 2006
991
US
I've never been one to make a new years resolution, but I think I'll try to learn powershell this year. Last year I took a crack at learning VBScript/WMI/ADSI and hopefully I'll have just as much luck learning PowerShell this year. I found this site ( that I like for the simple fact that the majority of the examples stay away from aliases. There is nothing wrong with aliases since it requires less typing, but for those of us learning it can make it more difficult to understand.

example - you see something like: ps | gm | ft -auto
If you're new to a language are you going to have any idea of what's going on with that line?

written out it's: get-process | get-member | format-table -auto
which isn't too much better if you're unfamiliar with the language, but it gives you a better idea of what's going on.

Just my two cents.

Anyone else come across or know of any other good sites?

dm4ever
--------------------------------------------------------------------------------
My approach to things: K.I.S.S - Keep It Simple Stupid
 
Just the Microsoft scripting site has worked wonders for me. Particularly helpful was the converting vbscript to powershell section.

I think the first "must have" commands are "get-command" and "get-help". Once you learn the syntax and how to use the help, it's pretty easy. I've been able to convert some of my vbscripts and batch scripts over to PowerShell within a very short time without much trouble.

For instance, to get drive space on a remote computer, format everything nicely and perform some math function to make the sizes more readable, I did:

Code:
Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -ComputerName SRVNAME | Select-Object -Property Name,FreeSpace | ForEach-Object -Process {$_.FreeSpace = [math]::round(($_.FreeSpace)/1024/1024); $_} | Format-Table -Property Name,FreeSpace -autosize | Out-File -FilePath C:\FREESPACE.txt -append

It's surprisingly easy figure out the parameters and use other cmdlets to modify the output, e.g. "Format-Table". And adding variables and running loops is not hard to figure out either.

Very cool stuff. I actually requested this forum be created to the moderators as well. I think there will be a lot of interest and usefulness for this.
 
For the free space you can do your math by dividing by 1MB or 1GB instead of 1024/1024.

($_.FreeSpace)/1MB

dm4ever
--------------------------------------------------------------------------------
My approach to things: K.I.S.S - Keep It Simple Stupid
 
Huh, didn't know that. Look, you get the first star ever in the PowerShell forum. Congratulations.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top