Powershell V3 is built in Windows 8 and available for Windows 7 SP1 and Windows Server 2008 R2 SP1.
.NET Framework 4 is required.
You can download Powershell V3 which is part of the Windows Management Framework 3.0 from here.
There are some really nice new features and I will combine all of them in one script to show you how powerful it is.
Look at this example:
<code>
Workflow test{
[Parallel]{
[Parallel]{
& {Write-Output -InputObject "The computer will restart in 10 seconds."; Start-Sleep -Seconds 10; Restart-Computer}}
&{foreach($i in 1..5){
$i | out-file -FilePath C:\Users\Tester\Downloads\test.txt -append}
}
}
}
$trigger = New-JobTrigger -AtLogOn
Register-ScheduledJob -name Myjob -ScriptBlock {Write-Output -InputObject "Written after reboot." | out-file -FilePath "C:\Users\Tester\Downloads\test.txt" -append -Force; Unregister-ScheduledJob -Name MyJob} -Trigger $trigger
test
</code>
In this script I'm writing from 1 to 5 to a file, then warning the computer will be restarted and creating a Scheduled Job that will write something to a file after reboot then Unregister itself. The trigger to start the job is at log on. All this is inside a Workflow with Parallel computation.
When you run it, it will first schedule the job, then write to the file and finally restart the computer.
Pretty cool isn't?
Another nice cmdlet is the Show-Command.
You can use it in front of any other cmdlet to get a GUI where you can specify the attributes. Then you can run it from the GUI or copy the command and use it in the shell.
Try it: Show-Command Get-Process
Powershell is sooo cool. If you don't use it, start now! It's extremelly powerful.
No comments:
Post a Comment