Powershell Script to Change Windows 7 User Profile Folders to UNC locations
i still new scripting , powershell. i have simple question. i tasked create pretty basic ps script use in our windows 7 rollout following:
- change location of desktop user's home folder on network drive. (what call h:\ drive)
- change location of favorites folder user's home folder on network drive. (what call h:\ drive)
this came , need:
## variables $newdesktoppath = 'h:\desktop' $newfavoritespath = 'h:\favorites' $userprofilepath = "$env:userprofile" $key1 = "hkcu:\software\microsoft\windows\currentversion\explorer\user shell folders" $key2 = "hkcu:\software\microsoft\windows\currentversion\explorer\shell folders" ##change registry settings change set-itemproperty -path $key1 -name desktop $newdesktoppath set-itemproperty -path $key2 -name desktop $newdesktoppath
set-itemproperty -path $key1 -name favorites $newfavoritespath set-itemproperty -path $key2 -name favorites $newfavoritespath remove-item $userprofilepath\desktop -recurse -force remove-item $userprofilepath\favorites -recurse -force ##reboot needed complete process ##delete ## in front of next line automate ## restart-computer
of course, finished this, powers decided rather have path unc path rather drive letter.
i found there registry setting network drives called hkey_current_user\network lists of mapped share drives logged in user. in key called h, there string called remotepath (type - reg_sz) has information need redo script.
i found if use get-itemproperty hkcu:\network\h –name “remotepath”
i following results:
pspath : microsoft.powershell.core\registry::hkey_current_user\network\h
psparentpath : microsoft.powershell.core\registry::hkey_current_user\network
pschildname : h
psdrive : hkcu
psprovider : microsoft.powershell.core\registry
remotepath : \\mis\mishome\mjd
so tried changing script this:
$remotepath = (get-itemproperty hkcu:\network\h –name “remotepath”) $newdesktoppath = “$remotepath\desktop” $newfavoritespath = “$remotepath\favorites”
unfortunately output $newdesktoppath this:
@{remotepath=\\mis\mishome\mjd}\desktop
so here simple question - how data (\\mis\mishome\mjd) in remotepath assigned variable end resulting variable $newdesktoppath this:
\\mis\mishome\mjd\desktop
thanks in advance.
thanks reply. after trying suggestion along 1 try , use trim tools, got way wanted.
here code worked. i adding if -then clean remove-item section, need. now play the windows 7 libraries. i found module, not having luck running it.
$remotepath = (get-itemproperty hkcu:\network\h –name remotepath) $newdesktoppath = $remotepath.remotepath + "\desktop" $newfavoritespath = $remotepath.remotepath + "\favorites" $userprofilepath = "$env:userprofile" $key1 = "hkcu:\software\microsoft\windows\currentversion\explorer\user shell folders" $key2 = "hkcu:\software\microsoft\windows\currentversion\explorer\shell folders" set-itemproperty -path $key1 -name desktop $newdesktoppath set-itemproperty -path $key2 -name desktop $newdesktoppath set-itemproperty -path $key1 -name favorites $newfavoritespath set-itemproperty -path $key2 -name favorites $newfavoritespath remove-item $userprofilepath\desktop -recurse -force remove-item $userprofilepath\favorites -recurse -force ##reboot needed complete process ##delete ## in fron of next line automate this
thanks again.
matt
Windows Server > Windows PowerShell
Comments
Post a Comment