Showing posts with label sleep. Show all posts
Showing posts with label sleep. Show all posts

Wednesday, April 4, 2012

IP Address Release, Renew using PowerShell.


Hi,

This is a very common task which is nearly performed by every End-user and IT Admin and Engineers. Normally we use "IPCONFIG /Release" to release the IP-address and "IPconfig / Renew" to renew or getting a new IP Address.

In some powershell script you may need to do this ip config /release and renew task. We can use native "IPconfig" command to achieve this. But there is an another way to do the same. Using WMI.
Download the script from here :

In variable $ethernet we are querying class Win32_NetworkAdapterConfiguration and using where-Object cmdlet we are choosing those adapter which have IP Enabled and have DHCP Enabled selected in there IP Configuration

than on each adapter we are using wmi method ReleaseDHCPLease()  first and then RenewDHCPLease() .

Download the script from here: http://gallery.technet.microsoft.com/scriptcenter/Renew-IP-Adresses-Using-365f6bfa

################################
$ethernet = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where { $_.IpEnabled -eq $true -and $_.DhcpEnabled -eq $true}  
foreach ($lan in $ethernet) {
       Write-Host "Flushing IP addresses" -ForegroundColor Yellow
       Sleep 2
       $lan.ReleaseDHCPLease() | out-Null
       Write-Host "Renewing IP Addresses" -ForegroundColor Green
       $lan.RenewDHCPLease() | out-Null
       Write-Host "The New Ip Address is "$lan.IPAddress" with Subnet "$lan.IPSubnet"" -ForegroundColor Yellow
       }
#############################################
Download the script from here: http://gallery.technet.microsoft.com/scriptcenter/Renew-IP-Adresses-Using-365f6bfa

30-03-2012 15-41-48

I hope that it may help someone.

Thanks

Aman Dhally

Thursday, February 23, 2012

Using BEEP sound in PowerShell Scripts.


Hi,

After watching the valentine post of “Jeffery Hicks” I started playing with $([char]) characters. And while working with these characters I found a great character that is character 7.

23-02-2012 12-07-13

So what is interesting in character number 7?, it is a Beep Sound. For example if  in your script you are rebooting the server or laptop we can provide 3 beeps for rebooting. Or  we can  set a beep after every task or command finished his task.
Cool isn’t..

try this script.

Download Script from Here: http://gallery.technet.microsoft.com/scriptcenter/Using-BEEP-sound-in-f637bb48
#### save it as beep.ps1 or so....
Write-Host "I am going to reboot the Laptop after 3 Beep" -ForegroundColor Red
$([char]7)
write-Host "Beep 1 " -ForegroundColor Green
sleep 1
$([char]7)
write-Host "Beep 2 " -ForegroundColor Green
sleep 1
$([char]7)
write-Host "Beep 3 " -ForegroundColor Green
sleep 1
Write-Host "`n"
Restart-Computer -Force -WhatIf
#################################

and the output is like below. Our computer is going to reboot after 3 beeps...

23-02-2012 12-09-26

Download Script from Here: http://gallery.technet.microsoft.com/scriptcenter/Using-BEEP-sound-in-f637bb48

Thanks for reading,
Aman Dhally
messenger_freak_adp1 (30)