创建powershell脚本以在桌面上启用显示+使用主机名重命名

时间:2013-06-24 09:17:47

标签: powershell windows-server-2008-r2

我只是一名初级程序员,刚刚开始编程,因为我的工作要求我创建一些方便的PowerShell脚本,我想知道你是否可以帮我一个特定的。

我们有很多客户拥有大量服务器。当他们新安装时,我会检查它们,然后我们定期进行维护。因为每个客户都有多个具有不同角色的服务器,所以我希望桌面上有“计算机”图标。 我可以点击开始 - >右键单击计算机 - >启用“在桌面上显示” 此外,我想将此计算机图标重命名为主机名(因为主机名告诉我它在域中的作用)

现在我的目标是创建一个powershell脚本,该脚本使用域名中所有服务器的主机名创建此计算机图标。

我试图搜索通常的搜索引擎并想出了这个:

1)使用regedit找到[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}将LocalizedString重命名为LocalizedString.Old 2)现在切换到Regedit32创建一个新的VALUE类型Expand_SZ将它命名为LocalizedString在XP和带有SP3的Windows 2000上将LocalizedString替换为%Username% at %Computername%

哪个不合适,因为我们使用的是W2K8R2SP1服务器。 之后我最终得到了这个脚本:

$ComputerName = "Localhost"
$Hive = "CurrentUser"
$Key = "Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel"
$MyComputer = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
$UserFiles = "{59031a47-3f72-44a7-89c5-5595fe6b30ee}"
$Kind = [Microsoft.Win32.RegistryValueKind]
$RegHive = [Microsoft.Win32.RegistryHive]$hive
$RegKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($RegHive,$ComputerName)
$MyComputerValue = ($RegKey.OpenSubKey($Key)).GetValue($MyComputer)
$UserFilesValue = ($RegKey.OpenSubKey($Key)).GetValue($UserFiles)
if ($MyComputerValue -eq $null -or $MyComputerValue -eq 0)
{
    $Computer = $regKey.OpenSubKey($RootKey,$true)
    $Computer.SetValue($MyComputer, 1,$Kind::DWord)
}
if ($UserFilesValue -eq $null -or $UserFilesValue -eq 0)
{
    $User = $regKey.OpenSubKey($RootKey,$true)
    $User.SetValue($UserFiles, 1,$Kind::DWord)
}

这似乎没有做任何事情。

我知道这个注册表项用于桌面上的计算机:

“{20D04FE0-3AEA-1069-A2D8-08002B30309D}”=dword:00000000

继续搜索...... 所以我发现了这个:

To show the ‘My Computer’ icon on the desk"text-decoration:underline;">
[HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel]
Name = {20D04FE0-3AEA-1069-A2D8-08002B30309D}
Type =REG_DWORD
Value = 0
To change the ‘My Computer’ icon to computer or user name:
[HKCR\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}]
Name = LocalizedString
Type = REG_EXPAND_SZ
Data value = %computername% or any combination you like – eg %username% %computername%

然而第二部分一直给我一个错误,即使我可以让它工作,我想运行脚本onces并且域中的所有服务器都应该有这个更新。

感谢您提供帮助。

致以最诚挚的问候,

尼克

1 个答案:

答案 0 :(得分:0)

更改HKCR\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\LocalizedString仍适用于Server 2008 R2,但您需要获取密钥的所有权并授予管理员对其的完全访问权限。