Showing posts with label set-itemproperty. Show all posts
Showing posts with label set-itemproperty. Show all posts

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

Monday, August 5, 2013

Powershell and MS Office : Setting User Initials in MS Office using Powershell.

 
Hi,

I hope you all are doing fine and enjoying my blog post.

I think we covered lots of things from setting wallpapers using Powershell to the generating reports from Active Directory, and this shows how powerful Powershell is and how we can use it in our various task to automate.

I simply love Powershell, not because it is Powerful but because it is one of (I want to say only) scripting language available, which is easy to learn and easy to use.

Ok, now lets discuss about my today’s task.

If in your company users are heavily using Word, Excel, PowerPoint, then you are aware from how, valuable are comments in.

To add a comment, you have to click on “Review ” tab and need to click on “New Comment” icon.
So now you may be ask, what is the big deal?

Nice question, when few users, or any team , works on a single file, and when they add comments in to the file, the comments are shown as “User Initials”.

So, what if your “User Initials” in Ms Office are wrong, then no one knows who commented an who added the notes.

Download link : http://gallery.technet.microsoft.com/scriptcenter/Fix-Users-Initial-in-35c2801b

05-08-2013 15-59-16

you can see my user initials are set wrong. and when i add comments they are coming as “SAM” rather then “AD”.

05-08-2013 16-31-06

This is a problem, for example, if you have 100+ user or so and incase few one’s user initials are wrong, how you are going to fix it?

Manually? Yes, you can, but, that is not a good option for scripters.

Powershell Script? Awesome, let see how we are do this.
This user initials for Ms Office application are stored in, 
HKCU:\Software\Microsoft\Office\Common\UserInfo” in key “UserInitials”.
In this script.We are going to set this key using “$env:USERNAME” environment variable.
Here is the script code.

# stroing $env:Username in to  a Username variable
$userName =  $env:USERNAME

# Checking the current  Initials in the registry and storing in a variable
$oldInitials = (Get-ItemProperty -Path HKCU:\Software\Microsoft\Office\Common\UserInfo).UserInitials

# spliting username
# if your username had space you can use => $split = $username.Split()
$split = $username.Split(".")

# joining spiting username and getting a first words only
switch ($split.Length)
              {
                     0      { Write-Warning "Not able to find username." ; break         }
                     1      { $newUserInitials =  $split[0].Remove(1)   ; break    }
                     2      { $newUserInitials =  $split[0].Remove(1) + $split[1].Remove(1)   ; break     }
                     3      { $newUserInitials =  $split[0].Remove(1) + $split[1].Remove(1)  + $split[3].Remove(1)    ; break  }
                     4      { $newUserInitials =  $split[0].Remove(1) + $split[1].Remove(1)  + $split[3].Remove(1)  +  $split[4].Remove(1)   ; break  }
                     5      { $newUserInitials =  $split[0].Remove(1) + $split[1].Remove(1)  + $split[3].Remove(1)  +  $split[4].Remove(1)  + $split[5].Remove(1) ; break  }
              }



# if old user intitails not matched with Our one
if ( $oldInitials -ne $newUserInitials )
       {
       set-ItemProperty -Path HKCU:\Software\Microsoft\Office\Common\UserInfo -Name UserInitials -Value $newUserInitials -Force
       Write-Host "User Initials Fixed" -ForegroundColor 'Green'
       }
else
       {
       Write-Host "User Initials matched."
       }
In above screenshot, you have seen that my user initials are set wrong in MS Office.

Now lets run the script and see and if this fix it. , Make sure that you all Office app are closed .

I run the script and and it is showing me that it fixed it.

05-08-2013 16-09-15

Now open any office app and see if this really fixed it.

Seems good.

05-08-2013 16-09-30 

now add some comments.

Yaay.!!!!!. it fixed.

05-08-2013 16-10-56

Download link : http://gallery.technet.microsoft.com/scriptcenter/Fix-Users-Initial-in-35c2801b

Thanks
Aman Dhally
clip_image001 clip_image002 clip_image003 clip_image005clip_image007











Thursday, August 1, 2013

Set Random Wallpaper on your Desktop using Powershell


Hi,

We all love wallpapers. I and love them too.

Sometime they reflect our moods too. I have a huge collection of Wallpapers and i love to change my wallpapers in once or twice a week.

In the time of windows XP, i used to have a software which changed my wallpaper daily when i login to the laptop.

To be frank i never used to have a any desktop changer software in my windows7 laptop.

Few days ago i just write a small snippet code to change my wallpaper on daily basis.

How i do that ,

It is simple, Powershell + Registry and that all.

Download Link : http://gallery.technet.microsoft.com/scriptcenter/Set-Random-Wallpaper-Using-e79e423

Lets do it.

The below variable is storing the path to my Pictures. {you can change it to with yours ,, or you can use Join-Path $env:USERPROFILE  -ChildPath Pictures .}

$myPictureFolder = 'C:\Users\aman.dhally\Pictures\’

Now, i am running Get-ChildItem (dir) on our Picture folder, and using Get-Random cmdlet, i am choosing any single  wallpaper randomly.

$getRandomWallpaper = Get-ChildItem -Recurse $myPictureFolder |where {$_.Extension -eq ".jpg"}  | Get-Random -Count 1

Now we are using Set-ItemProperty to set the select wallpaper to the desktop.
To update the desktop we have to use rundll32.exe and to be frank, until we don’t run the  "

rundll32.exe user32.dll, UpdatePerUserSystemParameters

” code 3-4 time wallpaper wont change. or we reboot the laptop.

Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $getRandomWallpaper.FullName 
rundll32.exe user32.dll, UpdatePerUserSystemParameters
Completer Script
$myPictureFolder = 'C:\Users\AD\Pictures\WallPapers\IronMan'

# $myPictureFolder = Join-Path $env:USERPROFILE  -ChildPath Pictures
$getRandomWallpaper = Get-ChildItem -Recurse $myPictureFolder |where {$_.Extension -eq ".jpg"}  | Get-Random -Count 1
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $getRandomWallpaper.FullName 

rundll32.exe user32.dll, UpdatePerUserSystemParameters  
rundll32.exe user32.dll, UpdatePerUserSystemParameters
rundll32.exe user32.dll, UpdatePerUserSystemParameters

Download Linkhttp://gallery.technet.microsoft.com/scriptcenter/Set-Random-Wallpaper-Using-e79e423


Note: I tested this on windows 7 32 bit only.
Thanks
Aman Dhally
clip_image001 clip_image002 clip_image003 clip_image005clip_image007

Wednesday, July 24, 2013

Changing Desktop Wallpaper Positions using Powershell.

 

Hi,

Yesterday i blogged about changing Desktop background colour using Powershell.

Today we are going to change the Desktop Wallpaper Position using Powershell. Like the previous post this is again a registry tweak.

Windows Desktop wallpaper has 5 types of  Picture Position.

  1. Center
  2. Fill
  3. Fit
  4. Stretch
  5. Tile

The registry key which retains these settings is HKey_Current_User\Control Panel\Desktop and the registry key name is “WallpaperStyle

 

Setting “WallpaperStyle” reg key value
Center 0
Fit 6
Fill 10
Stretch 2
Tile 0

Lets try it :)

24-07-2013 19-13-17

I have  centrally positioned wallpaper of my daughter “Manya”  and lets changed the position to FIT one.

Set-ItemProperty 'HKCU:\Control Panel\Desktop' -Name "WallpaperStyle" -Value 6

24-07-2013 19-15-09

now log off and log-in again.

and here you go , the “Picture Position” is set to “Fit.”

24-07-2013 19-16-54

Now lets set the wallpaper position to “Fill”

Here is our code, run it,

Set-ItemProperty 'HKCU:\Control Panel\Desktop' -Name "WallpaperStyle" -Value 10

24-07-2013 19-18-00

log-off and re login again. and our “Picture Position is set to fill :)

24-07-2013 19-18-49

Now, lets set it to the “Stretch”

run the code

Set-ItemProperty 'HKCU:\Control Panel\Desktop' -Name "WallpaperStyle" -Value 2

24-07-2013 19-19-46

log-off and re-login again , and the wallpaper is set to “Stretch” now.

24-07-2013 19-20-30

if you want to set wallpaper as TILE then we have to tweak two keys. the WallpaperStyle" and “TileWallpaper"

To tile the wallpaper, we need to set “TileWallpaper" to 1

run the script code.

Set-ItemProperty 'HKCU:\Control Panel\Desktop' -Name "WallpaperStyle" -Value 0

Set-ItemProperty 'HKCU:\Control Panel\Desktop' -Name "TileWallpaper" -Value 1

24-07-2013 19-23-24 

Log-off and log-in again.

and i can see my cute bunny’s picture all over the monitor.. :) . It successfully positioned as tile.

24-07-2013 19-24-45

Okies. now lets set every thing back to normal.

I am setting wallpaper as “cantered” positioned  and tile key to off.

Set-ItemProperty 'HKCU:\Control Panel\Desktop' -Name "WallpaperStyle" -Value 0

Set-ItemProperty 'HKCU:\Control Panel\Desktop' -Name "TileWallpaper" -Value 0

24-07-2013 19-25-30

log-off and log-in again.

and you can see, there is no tile and wallpaper is centrally positioned.

24-07-2013 19-27-09

I hope that you will find it handy and helpful.

Thanks
Aman Dhally
 
 
clip_image001 clip_image002 clip_image003 clip_image005clip_image007