Tuesday, 15 March 2016

How to Zip and UnZip files using PowerShell

11:31 am

Today we are going to Learn all about Compressing and Decompressing a file using Powershell. So lets get started.

Powershell 5.0 have lots of features added to its feather. One of them is Zipping and Unzipping . Powershell 5.0 contains 2 functions by default for Zipping and Unzipping a file i.e. Compress-Archive and Expand-Archive

Syntax :

Zip : Compress-Archive -path <Source_File_Path> -DestinationPath <Destination_File>

Unzip : Expand-Archive -path <Zip_file_path_to_Extract> -DestinationPath <Destination_path_where_to_Extract> 





>_ If you are using Powershell version below 5.0 then you can achieve the same by Calling a Class.

ZIP - FILE


Add-Type -Assembly "System.IO.Compression.FileSystem" ;
[System.IO.Compression.ZipFile]::CreateFromDirectory("E:\The Powershell Geek", "E:\sample.zip")


UNZIP -FILE

Add-Type -Assembly "System.IO.Compression.FileSystem"
[System.IO.Compression.ZipFile]::ExtractToDirectory("E:\sample.zip", "E:\")




Hope you all liked it.. Keep Learning and do share. If you have any queries related to Powershell then do comment we will take it up in our next post.

Saturday, 5 March 2016

Execution Policy in Powershell

3:59 pm
How to get and set the Execution Policy

Execution Policy in Powershell

Execution Policy in Powershell helps to determine the type of scripts that can run on a particular system. 


There are different types of Execution Policy in Powershell :

1. RESTRICTED

It is the default execution policy in Powershell. It means it doesn't allow any Powershell script(*.ps1) to execute by default. In order to provide security, Microsoft suggests Restricted policy by default so that none of malicious code can be executed by double clicking or running it. 

2. ALL SIGNED 


All the Scripts should have a digital signature from a trusted publisher, then only you will be able to execute the Script else Script will not be executed. This is applicable for the local scripts also which you write of your own, you will need to assign a certificate to it example Self Signed Certificate.
3. REMOTE SIGNED

Local script files doesn't need any signature( they can be executed) but scripts downloaded from any internet source will require Signature from a Trusted publisher in order to get executed. 

4. UNRESTRICTED 

This Policy is not recommended by Microsoft since it allows any script to run , although it will prompt for permission if the script is downloaded from Internet. This policy is least secure so avoid keeping this. 

5. BYPASS

This works on the same functionality of Unrestricted policy. Only difference is we can skip the prompt for permission in Bypass.

How to Find and Set the Execution Policy :

Get-ExecutionPolicy
Set-ExecutionPolicy <Type_Of_ExecutionPolicy> e.g. Set-ExecutionPolicy RemoteSigned



Hope you all like the post. Keep commenting, and DO SHARE!

Contact us

Name

Email *

Message *

Recent

recentposts

Random

randomposts