Thursday, May 19, 2016

PowerShell cmdlet of the Day : Expand-Archive

 

Yes, Yes, this was the most awaited cmdlet in the PowerShell world... Wow!! it's one of the coolest command ever exists for system admins.

Now , we can write scripts to unzip ZIP files, I mean, can write more efficient scripts to unzip files ( without using .net code).

Ok! let's be less dramatic.

If you want to unzip a zip file using PowerShell, then there is a cmdlet available for it, named Expand-Archive.

It's syntax  is simple, provide the path of .Zip file, then the path of Destination where you want to extract files. that's all!

Expand-Archive -Path C:\Users\aman.dhally\Desktop\PingData.zip

-DestinationPath C:\temp\Data\ -Force -Verbose

In the above command, we are unzipping the PindData.zip to the folder C:\temp\Data. The parameters are quite self-explanatory.

m1

In the above screenshot you can see that the above command has run successfully and it' unzip the archived.

Now you can write script to unachieve your backups. :D

:)

With Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel
for PowerShell video tutorials. You can download all of my scripts from “Microsoft
TechNet Gallery”.

Wednesday, May 18, 2016

PowerShell cmdlet of the Day : Format-Volume

 

Do you remember old days, when we used to have Format.exe to create and format partitions? Good old days! Huh! after that comes the GUI, afterwards that everything is done by mouse clicks :D.

In windows8 and later version of it, PowerShell included a cmdlet Format-Volume, which format the new or existing partition. Cool!

You can use the Format-Volume in lot's of way, but the most basic and widely use of this command is to format a  partition.

The basic command to do it is :

Format-Volume -DriveLetter D -FileSystem NTFS -Full -Force

D1

In the above command, we are formatting the D drive and formatting as a NTFS file system and by providing -Full we are asking it to fully format it ( it will take time, if you don't use the -Full parameter , it used the -quick by default).

Simple :) isn't.

To know more about the cmdlet  visit : https://technet.microsoft.com/en-us/library/hh848665(v=wps.630).aspx 

 

With Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel
for PowerShell video tutorials. You can download all of my scripts from “Microsoft
TechNet Gallery”.

Tuesday, May 17, 2016

PowerShell cmdlet of the Day : Invoke-History

 

You might be thinking, what "Invoke-History" does?

Actually it re-run the command which you run before running "Invoke-History", in simple words , this cmdlet executes the latest command which you run in PowerShell console.

Aman Dhally, Manya Kaur

In the above screenshot you can see, that it runs the last executed command. You might be thinking, it's not helpful, you can re-run the last run command by pressing UP-Arrow and then hit enter, yes you are right, But (Sorry! there is always a BUT!).

In my previous post, when we run the Get-History cmdlet and I had mentioned that in the out of the Get-History cmdlet the property  ID is quite important, in Invoke-History you can use the -ID parameter to run the specific command which is stored in the History :D .

Aman Dhally, Manya Kaur

In the above screenshot the Invoke-History will execute the command which have the ID number 17 in History.

Cool! I am right ;)

With Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel
for PowerShell video tutorials. You can download all of my scripts from “Microsoft
TechNet Gallery”.