Thursday, September 26, 2013

Powershell Techniques : Lock Your Workstation using Powershell.

 

In my previous post, I created test button on Login Screen changer GUI,  when you clicked on them it lock your workstation.

Capture

I got few queries that which code I used behind the above Test button.  I used the below code to lock the workstation.

 $shell = New-Object -com "Wscript.Shell"

 $shell.Run("%windir%\System32\rundll32.exe user32.dll,LockWorkStation")

Just shoot the above code and when you paste the last line, you computer will be locked.

I found it cool! i hope you may also like it.

Aman Dhally

clip_image001 clip_image002 clip_image003 clip_image005clip_image007

Monday, September 23, 2013

Powershell Tools : Windows Login Screen Changer GUI application.

 

Hi,

In my previous post, i described about, how to change login screen using Powershell.

In weekend I thought about to create a small Powershell GUI application to set a Login screen for us.

How to use it.

Run the script as Administrator and in a –Sta mode.

0

 

Click on Change Login Screen to choose the picture which you wan to set as login screen, make sure that the picture should be less then 254 kb in size.

You can click on Test button to test the current set Login screen.

If you want to set your login screen to default then click on “set to default button”.

1

 

Set a Lon screen:

  1. Click on “Change Login screen”
  2. Then choose you image and click on Open.

 

2

This will show you which pic you has chose as a login screen. Click on Test to test the login screen pictures which we has just choose.

3 

and here is the result :) .

IMG-20130919-00495

Download Link : http://gallery.technet.microsoft.com/Powershell-Application-303a17cb

 

I hope that you find is useful.

Aman Dhally

clip_image001 clip_image002 clip_image003 clip_image005clip_image007

Thursday, September 19, 2013

Change windows Login Screen using Powershell.


Hi,
We all love customization and personalize our laptop setting. Like we all (majority of) love to change our wallpapers.
windows-7-logon-background
I have few scripts, which rebooted a laptop twice thrice, on those scripts i use Logon screen as a information and “how to’s” board.
backgroundDefault
and if you want some fun , you can also change the login screen with your choice of picture.
How to change login screen?
  1. Make sure the picture which you want to set as Login Screen is less then 254KB
  2. Rename the picture to “backgroundDefault.jpg
  3. A2
Run Powershell as Administrator.

Now, we need to set “OemBackgroud” value to 1 in the registry

Set-ItemProperty -Path hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background 
 -Name OEMBackground -Value 1
 
A1

Now copy the “backgroundDefault.jpg”  to the "C:\Windows\System32\oobe\info\backgrounds\" folder.

Copy-Item -Force "c:\myscripts\backgroundDefault.jpg" 
 "C:\Windows\System32\oobe\info\backgrounds\" -Verbose

A3

Now, to test, lock you screen (Windows Key + L ) and see if logon screen is changed or not.

But mine is changed :)

IMG-20130919-00495




How to set login screen to default again?

To set logon screen to default again, set the OEM key to “0” again.

Set-ItemProperty -Path 
hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background  
-Name OEMBackground -Value 0

I hope that you find is useful.

Aman Dhally

clip_image001 clip_image002 clip_image003 clip_image005clip_image007

Saturday, September 14, 2013

PowerShell Techniques : Alias v/s Full Cmdlets usage.

 

Hi Everyone,

I hope you are enjoying your weekend.

This is my another post on Powershell techniques.

We all love Powershell alias's they are good and they handy and saved lots of key strokes.  I use Powershell alias a lot. But i have seen few Powershell scripter and they do use Powershell alias in their scripts. 

In Console

1 (fig. 1)

2(fig. 2)

You can see when we use alias in Powershell Console, it use less space and less key strokes,

Good, we know Alias are good so?

In Powershell scripts i don’t prefer to user Powershell alias. Powershell scripts are used by other too , we share the script , so if someone want to change anything or append anything then it is bit difficult  and intercept the code.

So for easy reading, easy interception using full cmdlets are very useful to use in the scripts.

3

Note :- This is my personal opinion and view. 

Happy Scripting ;)

That’s all for now.

Thanks

Aman Dhally

clip_image001 clip_image002 clip_image003 clip_image005clip_image007

Thursday, September 12, 2013

PowerShell Techniques : Commenting Scripts, it’s always helpful.

 

Hi,

I hope you are enjoying my Powershell Techniques series of web post. I always mention in most of my blog posts that, learning or memorizing what cmdlets do is really easy , but it is bit difficult to find techniques.

In my opinion these tips and trick or we can say techniques are universal, these are more then a logic and can apply anywhere and in any scripting language.

When you write Powershell script, it is always handy to add comments on them, as we know, in Powershell we use hash(#) character to add comments.

Why it is important to add comments?

In my point of view it is very important, because:

  1. If you are writing a long script, you will know what you are doing.
  2. If you want to share the script with one else,, they can also understand the script by reading comments.
  3. We can define a separate section for variable,function using comments.
  4. if we are using lots of foreach,if, loops, it is easy to identify ending of each loops.

 

In my scripts I use comments as separator. You can see that, I define a separate space for the Variable, Modules, Functions, So when next time, if i want to add of troubleshoot any functions, at that time i know where to look for them,

12-09-2013 23-09-27

It is always good to add comments above your code, so that you know what that code is doing.,This helps you and helps other to understand your scripts.

12-09-2013 23-16-52

If you are using multiple if/else or other loop and statements, then you can also use #comments in the end of } braces, you that you know which logic is applying on it.

image

That’s all for now.

Thanks

Aman Dhally

clip_image001 clip_image002 clip_image003 clip_image005clip_image007

Wednesday, September 11, 2013

PowerShell Techniques : Visual Formatting of the Powershell Scripts.

 

Hi,

I am finally back to India, and it is always good to be at home.

This week is a bit busy, catching up with my pending work.

Today while writing a new script I was checking few of my Old scripts. And i realised that my old scripts are bit hard to read , why? because of  improper formatting.

Formatting? why? why we need a formatting in a script? this is not a Word, PowerPoint document.

Yes, formatting is a essential and key part of the scripting, more neat and properly formatted your script is , more it is easy to read and easy to maintain.

For example.

11-09-2013 23-08-52

versus

11-09-2013 23-09-27

Now you can see that, reading script is bit easy in the second screenshot rather then the first one. This create a neat and clean type of scripts , rather then a messy one.

few tips and shortcuts.

  1. If you want to increase the indent of whole script, then just select whole script code and Press TAB.11-09-2013 23-14-44
  2. If you want to decrease the indent of whole script, select the script and press SHIFT + TAB
  3. To indent a single line, just press TAB
  4. To separate two section / function in the script, you can use a visual seprater like this, so that you know, another section is started.11-09-2013 23-20-23 

 

That’s all for now.

 


Thanks
Aman Dhally
clip_image001 clip_image002 clip_image003 clip_image005clip_image007