Friday, January 31, 2014

PowerShell Tips : Changing Monitor brightness using PowerShell.

 

 Do, you ever tried to change the monitor brightness using PowerShell. If not, than go and try it. It’s too cool.

You can use the below “WmiMonitorBrightnessMethods” class to set the brightness of the monitor. You need to use “WmiSetBrightness” method of the class to set brightness.

Do this:

1.       Set your monitor brightness to the full.

2.       Run the below command and see the result

 

(Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1,20)

 

clip_image002

 

Amazed, Your monitor brightness will be set to 20.  You can set the value of brightness from 0-100 .

Just change the value of 20 in above command from 0-100.

if you want you can convert it to function too J ..

Go and test it J .

In-case you got an error, “Not Supported” that means you display driver won’t support it.

 

Happy Weekend.

Thanks

Aman Dhally

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021

 

 

PowerShell and GUI : Working with GUI “Form” properties using PowerShell Studio 2012

 

In my previous post,Powershell Studio 2012 we had created a blank PowerShell GUI form, in this post, I am just sharing about few useful form properties.

Note: We are using Sapien PowerShell Studio 2012

Windows State of the form

If you want to run your GUI to me minimize, or maximize when they run, you are use the “WindowState” field property, to set it as per your needs, either, to stay, it Normal, Minimized or Maximized.

clip_image001[4]

 

Customize Cursor.

Do you want to use a specific cursor for your PowerShell GUI applications, Yes! , you can, using the “Cursor” field property, just click on “Cursor” and choose the cursor which you like to use.

clip_image002[4]

 

Setting Form Border Style

 

You, can also set the style of the form border, using “FormBorderStyle” field property. You can check the below table about the form border style vales and their effects on the form.

 

clip_image003[4]

 

Value

Effect on the form

None

With No Border,

Fixed 3D

You, can’t resize the form, with ICON on the top, with Maximize, Minimize and cancel button  {not able to spot any big difference}

Fixed Single

You, can’t resize the form, with ICON on the top, with Maximize, Minimize and cancel button

Fixed Dialogue

You, can’t resize the form, with NO  ICON, with Maximize, Minimize and cancel button

 

Sizable

You, can resize form, with ICON on the top, with Maximize, Minimize and cancel button

FixedToolWindow

A form with a close button only. You, can’t resize the form.

SizableToolWindow

A form with a close button only. You, can resize the form.

That’s all for today, See you in my next post

 

Thanks

Regards

Aman Dhally

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021

Tuesday, January 28, 2014

PowerShell and GUI : Creating a GUI form using PowerShell Studio

 

We all love PowerShell, because it is great tool for automation and creating scripts.

Sometimes GUI’s are useful too, sometime for fun and sometime it good to write our own tool for the company users.

Like creating a GUI toll about the information of users, disk space, or whatever you think of.

I use “PowerShell Studio 2012” for creating GUI’s. It is one of the best tool available out there for creating GUI’s, but unfortunate it is a paid one.

You can download the evaluation version of PowerShell Studio 2012 from this link : http://www.sapien.com/software/primalforms

I am writing these post by using “PowerShell Studio 2012”, but logic behind it is same.

As in GUI we are going to use Button, labels etc, and the functionality of these are same, in spite of how you are creating them.

Creating Form.

To create a new blank form,

1. Open PowerShell studio

2. Click on “New”

3. And click on “New Form”

4. clip_image001

5. It will show you few templates, choose one as per you need.

6. I am selecting “Empty Form”. And Click on “Select”

7. clip_image003

Form

Now, You, will see 3 screens, one is containing “Toolbox” which contain all graphic elements, in middle we have our new black form, and the third one the “Properties” windows. If you click any element, properties windows shows that element’s properties.

clip_image005

Customise form.

Now, let’s customize our form.

Changing form name.

To change the name of the form, click on the form, and in the property window , you see the “Text” field and in the front of it, you will see the value of the form, change is as per your need.

clip_image006

I am changing the value to “My First Form”.

clip_image007

You can see that the name of the form is changed.

clip_image009

Setting Transparency.

Sometime, you may want to look you form fancy, and a little bit transparent, to set the transparency of the form , we use the “Opacity” field of the form properties, by default it is set to 100%. You can set it you any values below 100% as per your needs.

clip_image010

I am changing the opacity of the form to 50%

clip_image011

Now run the file and you can see how transparent our form became.

clip_image012
Keep your form always to the top.

If you want to keep your GUI form, always on the top of the other windows, change the “Top Most” value to “false” to ”true”.

clip_image013

Changing form background.
Changing background colour.

To change the background colour for the form, click on “BackColor” under “Appearance” tab and and choose the colour which you like to have in you form.

clip_image014

clip_image016

Using image as background.

We can also use the image as background, , under “appearance” tab, click on “BackgroundImage”, and click on browse icon, and select the image which you want to use as background image.

clip_image017

Choose the image and click on “Open”

clip_image019

Now you can see that background image is set, and you can also set the “background image layout” to “Tile,Center,Stretch,zoom” by clicking on “BackgroundImageLayout” field properties.

clip_image021

clip_image022

That’s all for today. See you in next post.

Regards

Aman Dhally

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021

Monday, January 20, 2014

Part–3 : PowerShell and DHCP : Configuring the DHCP Scope DHCP Server

 

 

Part – 1 : PowerShell and DHCP : Installing DHCP Server Role on Server 2012

Part – 2 :PowerShell and DHCP : DHCP Post-Install Configuration

 

 

In my previous post, we do the Post-Install configuration task for the DHCP Server.  Now it’s time to configure the DHCP Sever Scope. We can going to do the below configuration.

Configuration.

 

DHCP Configuration

Name

ID

 

 

IP Address Scope

 

192.168.1.100

192.168.1.200

DNS Server

6

 

 

Gateway

3

192.168.1.99

 

Domain Name

15

Amandhally.net

 

Subnet Mask

 

255.255.255.0

 

 

We configure our DHCP server to give us the automatic IP Address from Range 192.168.1.100 to 192.168.1.200.  Subnet mask  is “255.255.255.0” our Gateway’s IP Address is 192.168.1.99 and the IP Address of our DNS Server is “192.168.1.99”, and as a domain name for DHCP IP, I am using amandhally.net.

Scope

 

Before setting scopes, I want to bind the specific LAN card for DHCP Server ( as I have 2 LAN cards on my server), I don’t want to run DHCP server service on all of My LAN Cards,  to do that, I can use “Set-DhcpServerv4Binding” cmdlet.

You can see I have 2 Ethernet cards on my machine, and I want to run the DHCP server on the LAN card named as “for_dhcp”.  

Note: I renamed this LAN card manually, from “Local Area Network” to “for_dhcp”.

Now run the below command.

Set-DhcpServerv4Binding -InterfaceAlias "for_dhcp" -BindingState $true

clip_image002

 

Once it done, let cross check it by running the Get-DhcpServerv4Binding cmdlet.

 

clip_image004

Perfect, the Ethernet is bind.

 

Setting Scope.

 

Now, we have to set a scope for the DHCP Server, so that he can start giving us the IP addresses.

$nameScope = 'DHCP Delhi'

$startIP = '192.168.1.100'

$endIP = '192.168.1.200'

$subnetMask = '255.255.255.0'

For my ease, I set my settings is variable, so that is easy to change later on {idea for scripting } , and save them as a script file for later use.

Above, I am setting the name of the scope to “DHCP Delhi” and the DHCP server start leasing the IP Address from “192.168.1.100” to end IP address of “192.168.1.200”. and my subnet mask will be “255.255.255.0”.

We have to set all of above using the “Add-DhcpServerv4Scope” cmdlet.

Now, Once you set the variable, run the below command. By using –State parameter to True, we are making this scope active.

Add-DhcpServerv4Scope -Name $nameScope -StartRange $startIP -EndRange $endIP -SubnetMask $subnetMask -State Active

Or

Add-DhcpServerv4Scope -Name 'DHCP Delhi'-StartRange '192.168.1.100' -EndRange $'192.168.1.200' -SubnetMask '255.255.255.0'-State Active

 

clip_image006

Once the above command run successfully, open your DHCP Server Manager and you can see that we have a new scope and that scope it Active.

clip_image008

 

Even our DHCP Sever is started giving the address to other laptop on the network too.

clip_image010

 

And I run Ipconfig /release and then Ipconfig /renew on another laptop and he gets the IP address from our server too.

clip_image012

 

Now, when you open the console, you can see our DHCP Server has given 2 ips to the computers.

Great J Isnt’

clip_image014

 

Till, now , we are successfully able to get the IP address on client system from our DHCP Server, But we won’t able to connect to Internet or other services, until we configure the Router and DNS options in the DHCP Server,

In our next blog post we are going to do that.

See you in my next blog post.

 

 

Regards
Aman Dhally
 
clip_image017 clip_image018 clip_image019 clip_image020  clip_image021

Thursday, January 16, 2014

Part 2–: PowerShell and DHCP : DHCP Post-Install Configuration


Part – 1 : PowerShell and DHCP : Installing DHCP Server Role on Server 2012

Doing Post-Install Configuration tasks


In my previous post, we go through the steps for installing the DHCP Server role on our windows server 2012. In this post we are going to do the DHCP Post Configuration tasks, which contains two steps for a standalone (Workgroup) server.
1.       Creating Security Groups
a.       DHCP Administrators
b.      DHCP Users
2.       Supressing the post-install configuration alert.

Note: I am running a non-domain server, which is just a standalone workgroup computer, if you want to do post-installation configuration on domain joined server, than the few steps are different as per compared to the workgroup server.

After installing the DHCP server roles, we have to complete the DHCP Server Post installation tasks. 

So, when you open the server manager console, you will see the below warning error, “Configuration required for DHCP Server at DHCP-Server1.

1

When you click on it, it will ask you to complete an action to Complete DHCP Configuration.

2
When you click on “Complete DHCP configuring”, you will see that it will ask to create 2 Security groups, one is “DHCP Administrators” and another one is “DHCP Users”.
Now Click on Cancel, yes on Cancel and go back to our PowerShell Console.

3

As, I told you before, that we will try to configure DHCP Server using PowerShell as much as we can.

Note : With Server 2012 R2, you can use the Add-DHCPServerSecurityGroup to add the two groups.No need to manually add them using ADSI! (Thanks to Sir Thomas Lee for suggestions.

Now, run the below script and then open Local users and Groups.

# Creating a group for DHCP Server
   # This Step is required for WorkGroup only server,
   # If your server is joined to the Domain, this steps are not valid.

$objectOU = [ADSI]"WinNT://$env:COMPUTERNAME"
$group = $objectOU.Create("Group","DHCP Users")
$group.CommitChanges()

$groupAdmin = $objectOU.Create("Group","DHCP Administrators")
$groupAdmin.CommitChanges()


4

Once you run the above script, you, can see that desired groups are created.

5

But, when you open Server Manager Console again you will see the same error again.

6

To supress this error, we need to change a registry settings, and then we need to restart the DHCP Server Service.
Run the below command to change the Registry value, to change the registry value, run the below command.

Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\ServerManager\Roles\12 -Name ConfigurationState -Value 2

7

Now, restart the DHCP Server Service.
Restart-Service -Name DHCPServer –Force

8

Now, open Server Manager again, and you can see there are not errors related to “DHCP Server Post Configuration”.
9

That’s all.
Now our POST configuration task is done, now next we have to start configuring the server…


Regards
Aman Dhally
clip_image017 clip_image018 clip_image019 clip_image020  clip_image021