Showing posts with label Write-Warning. Show all posts
Showing posts with label Write-Warning. Show all posts

Thursday, September 5, 2013

Powershell Techniques : Use While loop for rebooting laptop after 30 seconds with a informative message .




Hi,

I hope you all are doing well, I am in Italy for this week and enjoying Italian coffee.

Anyway.

In few of my scripts, before rebooting the laptop, I use Start-Sleep cmdlet to give a pause for 30-60 seconds.

We can do this easily using Start-Sleep 30.But, it is always good to show informative message on the screen so that user can know what is going on, to do that, I use while loop.

See the code below and it is very simple.


#variable
$second = 30

#While Loop

#while our $second variable is greater then 0
While ($second -gt 0 ) {

            # we are minus 1 with every look
            $second--
           
            # putting laptop sleeping for one seconds
            sleep 1
           
            # just a message
            Write-Warning "Computer will be restated in  $second"
           
            }

Logically this loop will run 30 times, until $seconds value is not come to zero.

Let's run the code and the result is. nice informative message about that laptops will be reboot in 30 seconds.




















Thanks

I hope you may like this. :) 


Thanks
Aman Dhally
clip_image001 clip_image002 clip_image003 clip_image005clip_image007







Monday, March 18, 2013

Powershell Script : Create An Encrypted Folder using Powershell.

Hi,

Windows Encryption is one of the best inbuilt security tool in windows7. My and my friends use windows encrypted file systems (EFS) a lot and may be you are using EFS in your windows environment.

Rather that create a whole DISK, My Documents, Desktop encrypted, I always prefer to create an encrypted folder somewhere on the disk and then put the files which you want to be encrypted in that encrypted folder.

I have written a small Powershell Script which created a encryption enabled folder on your desktop with folder name “Encrypted-Folder”.

You can download the script from this link http://gallery.technet.microsoft.com/scriptcenter/Create-Encrypted-Folder-6f0fe0c9

Script Logic
I have created a small flow charts on how this script works.
Encryption Script Sample
How it works.
  1. This script check for folder name “Encrypted-Folder” on your Desktop.
  2. If the Folder Exists.
    1. then it check if the attributes of the “Encrypted-Folder” is contains encrypted.
      1. If the Folder Attributes on “Encrypted-Folder”  contains “Encrypted”
      2. Then it won’t do anything.
      3. but
      4. If the Folder attributes doesn’t contains “Encrypted-Folder” 
      5. then
      6. it runs “cipher /e” command to make folder encrypted
  3. If the folder Does not exists,
    1. then this create a new folder “Encrypted-Folder”  on your desktop
    2. and encrypt it.
In this script i am using “cipher /e” to enable encryption. I have tested this script on windows7 and windows8 and it is working fine for me.
Screenshots.
18-03-2013 15-55-02
18-03-2013 16-15-19
18-03-2013 16-16-04

You can download the script from this link http://gallery.technet.microsoft.com/scriptcenter/Create-Encrypted-Folder-6f0fe0c9

That’s all for now.
Thanks
Aman Dhally
clip_image001 clip_image002 clip_image003 clip_image005clip_image007