Monday, April 13, 2009
Saturday, March 7, 2009
import-csv
Saturday, February 14, 2009
Tuesday, February 10, 2009
Pinging a Server from a Server you are not logged in to
So if you wanted server remote1 to ping server remote3 you could do something like this:
Get-WmiObject Win32_pingstatus –filter “Address =’remote3’” –computername remote1.| statuscode,address,_server
Sunday, January 25, 2009
rename computer
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
$ComputerInfo.rename($NewComputerName)
}
This script shows you how to rename computer by using WMI
How to use it :
& .\rename-computerName.ps1
rename-computername "MyNewComputerNAME"
And to reboot you can use WMI class Win32_OperatingSystem and its method reboot():
$OS = Get-WmiObject -Class Win32_OperatingSystem
$OS.reboot()
OR
shutdown -r -t 10 -f -c "Restart OS"
Users of PowerShell V2 (currently CTP3) can use the Restart-Computer cmdlet too. :)
DETAILED DESCRIPTION
The Restart-Computer cmdlet restarts the operating system on the local and remote computers.
You can use the parameters of Restart-Computer to run the restart operations as a background job, to specify the authentication levels and alternate credentials, to limit the operations that run concurrently, and to force an immediate restart.
This cmdlet does not require Windows PowerShell remoting unless you use the AsJob parameter.
Tuesday, January 13, 2009
regular expressions
Windows PowerShell: Writing Regular Expressions
More Powershell RegEx fun (playing with ‘route Print’)
Regular expressions in PowerShell and Perl
Windows PowerShell in Action: Working With Text and Files in ...
Regular Expressions with Windows PowerShell
The PowerShell Guy : Regular Expressions and PowerShell Part 1
The PowerShell Guy : Regular Expressions and PowerShell Part 2
Effective PowerShell Item 9: Regular Expressions - One of the ...
Regular Expression HOWTO
Learning to Use Regular Expressions
Regular Expressions - a Simple User Guide
What the Heck is a Regular Expression Anyway?
Regular Expression Library
How To: Use Regular Expressions to Constrain Input in ASP.NET
Regex tutorial by Gerd Ewald
Tuesday, January 6, 2009
Monday, December 22, 2008
Effective PowerShell from http://keithhill.spaces.live.com/
Effective PowerShell Item 1: The Four Cmdlets That are the Keys to Finding Your Way Around PowerShell, Effective PowerShell,
Effective PowerShell Item 2: Use the Objects Luke. Use the Objects
Effective PowerShell Item 3: Know Your Output Formatters
Effective PowerShell Item 4: Commenting Out Lines in a Script File
Effective PowerShell Item 6: Know What Objects Are Flowing Down .the pipe
Effective PowerShell Item 7: Understanding "Output"
Effective PowerShell Item 8: Output Cardinality - Scalars .
Effective PowerShell Item 9: Regular Expressions
Effective PowerShell Item 10: Understanding PowerShell Parsing
array compare
$arrFirst = get-content First.txt
$arrSecond = get-content Second.txt
New-Item "C:\Myworkplace\ps\FirstInSecond.txt" -Type file
New-Item "C:\Myworkplace\ps\FirstNotInSecond" -Type file
Foreach ($First in $arrFirst)
{
If ($arrSecond -contains $First)
{Add-content "C:\Myworkplace\ps\FirstInsecond.txt" $First}
Else
{Add-content "C:\Myworkplace\ps\FirstNotInSecond.txt" $First}
===
Monday, December 15, 2008
snap-ins
Get-PSSnapin -Registered
to add a snap-in
add-pssnapin [-name]
To see the installed snapins use
Get-PSSnapin
Removes Windows PowerShell snap-ins from the current console.
Remove-PSSnapIn [-name]
Saturday, December 13, 2008
SCRIPT CMDLETS now advanced functions
Under The Stairs: Parameter Attributes in PowerShell V2 CTP ...
Advanced Functions Support -confirm
A guide to PowerShell’s Advanced Functions
Advanced Functions with Powershell –Having some Fun
"CmdletBinding()]" google search add advanced function
Richard Siddaway's Blog
posh team blog advanced function search
Under The Stairs: Parameter Attributes in PowerShell V2 CTP ...
There is quite a lot to advanced functions so I am going to take a few posts to explore them fully
A Module to Create Modules and Advanced Functions
WINDOWS POWERSHELL 2.0 FEATURE FOCUS - SCRIPT CMDLETS
PowerShell 2.0 CTP - Script Cmdlets
MSDN Virtual Lab: Creating Windows PowerShell V2 Script Cmdlets
Powershell has a way to generate script cmdlets from an existing cmdlet.
turn some of these » Windows PowerShell » Windows PowerShell Script Repository into SCRIPT CMDLETS
Saturday, December 6, 2008
PowerShellASP
Wednesday, December 3, 2008
profile load issue solved
At line:1 char:2
+ . <<<< ‘C:\Users\Gaurav\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1′
Set-ExecutionPolicy remotesigned Notepad $profile
Set-ExecutionPolicy remotesigned
Sunday, November 30, 2008
Saturday, November 22, 2008
error handeling
Catch-Error.ps1
#Requires -Version 2 # Show-TryCatchFinally.ps1 # Demonstrates try/catch/finally in V2 # First, try something that will work Try { $I=1 } Catch {"Caught a problem in try 1" } Finally { "All done with 1st try" } # Now try something that fails $one=1 #$zero=0 Try { $one/$zero} Catch {"Caught a problem in try 2"}
Default Error Handling
Error handling in PowerShell scripts
Lunch Lesson: Error Handling in PowerShell
Methods for handling errors in PowerShell can range from simple to complex
for each
In PowerShell, foreach is both a statement and an alias to the ForEach-Object cmdlet.
While you might think that both of these examples do exactly the same thing, they do not.
Powershell tutorial 8 part 1
PowerShell tutorial 8 part 2
Essential PowerShell: Understanding foreach
Thursday, December 13, 2007
powershell pro site offerings pretty cool
3 Easy Steps to Get Information from Multiple Remote Computers…
Tutorials
PowerShell Introduction
PowerShell Console
PowerShell Cmdlet
PowerShell Aliases
Parameters, Objects, and Formatting
PowerShell Providers
Scripting Introduction
Variables, Arrays, and Hash Tables
Conditional Logic
PowerShell Loops
Functions and Filters
out-excel function +
Hey, Scripting Guy! How Can I Use Windows PowerShell to Automate Microsoft Excel
Powershell script to get network adapter names from a list of clients - Ying Li at myITforum.com = excel write
PowerShell script to compare a list of names in one excel column to a list of names in another column
One step further - to open a working range in excel worksheet
PowerShell script to open target worksheet in target workbook
Powershell script to open excel object (workbook)
PowerShell Script to compare two arrays
PowerShell for Testers Data-driven Testing Using PowerShell and Excel
PowerShell for Testers PowerShell Excel Functions - Release Candidate