Script to add Windows Gadget to user profile (PowerShell)
Introduction
This PowerShell script demo illustrates how to add windows gadget to user profile.
Scenarios
This question is asked by users in the TechNet forum. They just want to add windows gadget to user profile.
Script
Step 1: Click
Start, type
powershell in the search box on the Start Menu, right-click the
Windows PowerShell icon, and then click
Run Windows
PowerShell as administrator. If the
User Account Control dialog box appears, confirm that the action it displays is what you want, and then click
Continue.

Step 2: Run the script in the Windows PowerShell Console
, type the command:
Import-Module <Script Path> at the prompt.For example, Type
Import-Module C:\AddWindowsGadgetToUserProfile.psm1 This
is shown in the following figure.

Step
3: We can
type the command Get-Help Add-OSCWindowsGadgets to display
the entire help file for this function, such as the syntax, parameters, or examples.

Step 4: The script has three parameters:
- ComputerName: Specifies the computer which you want to run the add operation.
- GadgetSource: Specifies the path of Windows Gadgets source.
- UserName: Specifies the name of user profile.
You must specify two main parameters with the command. For example, type
Add-OSCWindowsGadgets -ComputerName “win7-2-pc” -GadgetSource “C:\Resource” -Verbose command as shown below:

Or
you can specify a user name profile with command.

Note: You may need to reboot or log off of windows for the change to take effect.
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
PowerShell
Edit|Remove
powershell
if($UserName)
{
Write-Verbose "copy the entire contents of $GadgetSource to $GadgetDestination\$UserName\AppData\Local\Microsoft\Windows Sidebar"
#copy items to specify user profile folder
Copy-Item -Path "$GadgetSource\*" -Destination "$GadgetDestination\$UserName\AppData\Local\Microsoft\Windows Sidebar" -Force -Recurse
}
else
{
$AllUsers = Get-ChildItem $GadgetDestination -Exclude Public
foreach($User in $AllUsers)
{
$UserName = $User.Name
Write-Verbose "copy the entire contents of $GadgetSource to $GadgetDestination\$UserName\AppData\Local\Microsoft\Windows Sidebar"
#copy items to each user profile folder
Copy-Item -Path "$GadgetSource\*" -Destination "$GadgetDestination\$UserName\AppData\Local\Microsoft\Windows Sidebar" -Force -Recurse
}
}
if($UserName)
{
Write-Verbose "copy the entire contents of $GadgetSource to $GadgetDestination\$UserName\AppData\Local\Microsoft\Windows Sidebar"
#copy items to specify user profile folder
Copy-Item -Path "$GadgetSource\*" -Destination "$GadgetDestination\$UserName\AppData\Local\Microsoft\Windows Sidebar" -Force -Recurse
}
else
{
$AllUsers = Get-ChildItem $GadgetDestination -Exclude Public
foreach($User in $AllUsers)
{
$UserName = $User.Name
Write-Verbose "copy the entire contents of $GadgetSource to $GadgetDestination\$UserName\AppData\Local\Microsoft\Windows Sidebar"
#copy items to each user profile folder
Copy-Item -Path "$GadgetSource\*" -Destination "$GadgetDestination\$UserName\AppData\Local\Microsoft\Windows Sidebar" -Force -Recurse
}
}
Prerequisite
Windows PowerShell 2.0
Additional Resources