Solved

How to add "Computer Description" locally to a Server via PowerShell.

Posted on 2014-03-21
38
2,370 Views
Last Modified: 2014-04-22
I need to add "Computer Description" to about 200 Servers in our domain.

Instead of RDPing to each Server and adding description, is there a faster way like using PowerShell.

I don't know PowerShell.

Please teach me step by step How to add "Computer Description" locally to a Server via PowerShell.

I am using a Windows 7 64bit computer.

Thank You.
ek
0
Comment
Question by:S T
  • 19
  • 9
  • 4
  • +2
38 Comments
 
LVL 14

Assisted Solution

by:Schnell Solutions
Schnell Solutions earned 50 total points
ID: 39946440
Hello,

As far as you need the Active Directory module for power shell it is easier if you make it from a domain controller following the next steps:

1. Logon to a DC

2. Open "Active Directory Module for Windows PowerShell" from the administrative tools

3. When the Windows Power Shell window opens, execute the following CMDLet:

Set-ADComputer <ComputerName> -Description <ComputerDescription>

If your computer name is PC01 and you want to use the description "Sales Department Computer" it would be like this:

Set-ADComputer PC01 -Description "Sales Department Computer"
0
 
LVL 29

Expert Comment

by:becraig
ID: 39946443
Depends on how you plan to do this.

If you have the powershell tools installed you can use set-adcomputer.

eg

gc serverlist.txt | % {
Set-Adcomputer $_  -Description "Whatever you want it to be"
}

Open in new window

0
 

Author Comment

by:S T
ID: 39946446
Hi schnellsolutions,

Do you mean I need "Active Directory module for power shell" in my Windows 7 PC ?

I would rather perform this from my PC than drom a DC.

Please advise.

Thanks.
st
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 29

Expert Comment

by:becraig
ID: 39946449
If you have a csv file with the name and desciption of the expected computer you can simply run this version

import-csv file.csv | % {
$description = $_.description
$server = $_.server
Set-Adcomputer $server  -Description  $description
}
                        

Open in new window

 


This is assuming you have a csv with the two columns:
Server, Description
0
 
LVL 29

Expert Comment

by:becraig
ID: 39946461
If you are doing this from windows 7 you can download KB958830 from
http://www.microsoft.com/download/en/details.aspx?id=7887]

Then simply run add / remove programs - turn windows features on and off and check and install Active directory module for windows powershell which will be found under:

Remote Server Administration Tools -> Role Administration tools.
0
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 39946465
I am presuming you want to change the Computer Desciption / Server Comment fields on the servers in question, and not the Active Directory computer description.

Please review the PowerShell script located at
http://www.computerperformance.co.uk/powershell/powershell3-rename-computer.htm

The script involving changing/adding/removing the Computer Description from multiple computers uses a comma-separated-values (csv) file to pass the computer names and descriptions to the script.

* You must have administrative permissions to all the destination computers.
* You must have remote WMI access to all the destination computers.

I hope this helps.
0
 
LVL 14

Expert Comment

by:Schnell Solutions
ID: 39946468
In order to use it from Windows 7:

1. Download the RSAT tools for Windows 7 from the Microsoft website

2. Enable the Active Directory module.
Navigate to Control Panel > Programs and Features > Turn Windows Features On or Off and select Active Directory Module for Windows PowerShell


3. Access the “Active Directory Module for Windows PowerShell”
Import the AD PowerShell module in your existing PowerShell session. Just use the following command:

Import-Module ActiveDirectory

Note: You need to have Active Directory web services running on at least one domain controller and the AD PowerShell module installed (These services run by default from DCs with windows server 2008 or 2012)
0
 

Author Comment

by:S T
ID: 39946568
Hi  schnellsolutions,

Your solution "Set-ADComputer PC01 -Description "Sales Department Computer"" adds Computer Description to Active Directory but not locally to the Server in "Computer Description"

I need it done on Server's Computer Description
0
 

Author Comment

by:S T
ID: 39946570
Hi WalkaboutTigger,

Regarding these:

* You must have administrative permissions to all the destination computers.
>>> I have domain admin access in our domain

* You must have remote WMI access to all the destination computers.
>>> Does this mean reoting into each Server and checking WMI ? Is there a faster way to check this ?
0
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 39946576
I would simply run the script and pipe all errors (using the script.ps1 2> error.log STDERR construct) to a logfile

Try it with a subset of 10 or 20 computers to ensure the script is doing what you intend it to do.
0
 

Author Comment

by:S T
ID: 39946633
Hi WalkaboutTigger,

Your link shows how to rename computers not how to add computer description.

Please advice.
0
 
LVL 15

Assisted Solution

by:WalkaboutTigger
WalkaboutTigger earned 50 total points
ID: 39946663
My apologies - I was in a rush - see script below

Get-Module -Name PSRemoteRegistry -ListAvailable

Import-Module PSRemoteRegistry

$CSVFile ="C:\ComputerDescriptions\ComputerDescriptions.csv"
$List = Import-Csv $CSVFile -Header ComputerName, ComputerDescription
Foreach ($Computer in $List) {
$strComputer = "$Computer.Computername"

# Registry variables for 'Computer description',

$Hive ="LocalMachine"
$Reg = "SYSTEM\CurrentControlSet\services\LanmanServer\Parameters\"
$Value = "srvcomment"
$Desc ="$Computer.ComputerDescription"

# Action part of script 
Set-RegString -Hive $Hive -Key $Reg -Value $Value -Data $Desc
}

Open in new window


See
http://www.computerperformance.co.uk/powershell/powershell-change-computer-description-registry.htm
for the source of the computer description registry code.

See
http://www.computerperformance.co.uk/powershell/powershell3-rename-computer.htm#PowerShell_Script_to_Rename_Multiple_Computers_
for the source code for using a CSV file to populate the fields.

I took these two and merged them together to form the code above.  The CSV file only needs two columns - ComputerName and ComputerDescription - in the format of
"ComputerName","Human-readable Computer Description"

You will need the Powershell module, PSRemoteRegistry, which can be downloaded from
http://archive.msdn.microsoft.com/PSRemoteRegistry

I hope this is useful.
0
 

Author Comment

by:S T
ID: 39946696
Hi WalkaboutTigger,

I understand that I need to run your pasted script in PSRemoteRegistry. How do I do this. Please send me step by step method.

Thx.
st
0
 

Author Comment

by:S T
ID: 39946729
Hi WalkaboutTigger,

I opened Windows PowerShell 64 bit as administrator

Then pasted your script.

But I get this error.ErrorPlease advice.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39947778
Remove the } in front of Get-Module - it does not belong there.
0
 

Author Comment

by:S T
ID: 39948026
Thanks Qlemo.

But it does not work.

My problem is that I dont know where and how to start.

Should I open Powershell on my domain PC as local admin or domain admin ?

Please advice.
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 400 total points
ID: 39948064
The code is missing the computer name to set the registry on, and contains much unnecessary code.
You best put the code into a file with an .ps1 extension, and call it in PowerShell by writing down the relative or absolute path to it. Let's assume you store both the CSV and PS1 file into C:\Scripts, and name the PS1 script SetPCDescription.ps1.
Import-Module PSRemoteRegistry

$Key = "SYSTEM\CurrentControlSet\services\LanmanServer\Parameters\"

Import-Csv 'C:\Scripts\ComputerDescriptions.csv' -Header Name, Description | % {
  Set-RegString -ComputerName $_.Name -Hive 'LocalMachine' $Key 'srvcomment' $_.Description
}

Open in new window

You call this by typing
  C:\Script\SetPCDescription.ps1
but you need to make sure the CSV file is of valid format without headers, that is it will look like:
PC1, Description1
PC2, Description2

Open in new window

or
"PC1", "Description1"
"PC2", "Description2"

Open in new window

You can use different delimiters like a tab, but then need to add e.g. -Delimiter "`t"  (for tab) to the Import-CSV command.
0
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 39948308
The code I provided generates an error, by design, if the necessary module is not already loaded, then loads the module.

I expected you were familiar with Powershell as that was the language you asked the script to be written in.

I can provide you a VBscript which does the same function, or a batch script.
0
 

Author Comment

by:S T
ID: 39948323
Thanks WalkaboutTigger, I want to do in Powershell. That way I'll learn it. Please send me a step by step method to set up the necessary module,
0
 

Author Comment

by:S T
ID: 39979298
Hi Qlemo,

Do I run your solution in my local domain PC or on a DC ?

Thx.
ek
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39979405
Doesn't matter, as long as the PsRemoting module is availablr locally.
0
 

Author Comment

by:S T
ID: 39979429
Hi Qlemo,

On my Windows 7 64bit Domain PC, I created this folder "Scripts" under C Drive

Path: C:\Scripts

Inside this folder I saved the following:
SetPCDescription.ps1
ComputerDescriptions.csv

I then opened Powershell 64bit from my Windows 7 64bit Domain PC.

Enabled PSremote
Ran SetPCDescription.ps1

But I get this error.
error
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39980005
The latter error results from either Remote Registry access blocked on that target machine (e.g. by firewall), or the machine being not available at the moment. You can try if
Import-Module PSRemoteRegistry

$Key = "SYSTEM\CurrentControlSet\services\LanmanServer\Parameters\"

Import-Csv 'C:\Scripts\ComputerDescriptions.csv' -Header Name, Description | % {
  Set-RegString -Ping -ComputerName $_.Name -Hive 'LocalMachine' -Key $Key -Value 'srvcomment' -Data $_.Description
}

Open in new window

works better - if the machine is not reachable, it should write out a yellow warning instead of a red error line.
0
 

Author Comment

by:S T
ID: 39992617
Hi WalkaboutTiggerPosted,
Can you provide me a VBscript which does the same function, or a batch script.


Hi Qlemo,
Please see error after pasting your script:
error
Thx.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39993026
Firstly and unrelated, Enable-PSRemoting is unnecessary here. You run that on a remote machine, if anything, not on the local one. But you don't need PS Remoting (WSMAN / WinRM) here, Remote Registry is a different access method.

The yellow warning message displays "[ComputerName]", so obviously you have such a line in the CSV file. Check your CSV file: It must not have headers, and all machine names have to be resolvable.

The error message is pointing towards missing privileges on the remote machine. The script is using your current credentials, so if you are neither a domain admin nor local admin on each remote machine, you do not have registry access (at least for writing).
0
 

Author Comment

by:S T
ID: 39995532
Thans Qlemo. Will keep trying next week and offer points.
0
 

Author Comment

by:S T
ID: 40008552
I've requested that this question be deleted for the following reason:

Solution does not work to my need.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40008553
Objection: "Solution does not work to my need" isn't a valid reason to delete the question. You didn't give feedback prior the deletion attempt, and that isn't helpful.

I provided you with a simple script and troubleshooting instructions. The ball is in your court, there is nothing we can add without your feedback.
0
 

Author Comment

by:S T
ID: 40009733
Some answers have helped. Please do not delete this question.
0
 

Author Comment

by:S T
ID: 40009774
Hi Qlemo,

Using solutions from "schnellsolutions" and "becraig" I was able to add Computer Description to Servers in Active Directory via PowerShell.

This is how I did it:

I created a csv file with the two columns - Server and Description

I named it “ComputerDescriptions.csv” and saved this csv file in SERVERDC\C\Scripts

I RDPied to SERVERDC as Domain Admin

I ran as Administrator "Active Directory Module for Windows PowerShell" (located in Apps)

I entered this command:

cd c:\scripts

I pasted this code into Powershell:

import-csv ComputerDescriptions.csv | % {
$description = $_.description
$server = $_.server
Set-Adcomputer $server  -Description  $description
}

This worked beautifully adding Description to all our Servers in Active Directory.

I still have not been able to add "Computer Description" locally on Servers using Powershell. Please advise.
0
 

Author Comment

by:S T
ID: 40009915
Hi Qlemo,

I think this code will work with changes in the 4th line. Can you check please.

import-csv ComputerDescriptions.csv | % {
$description = $_.description
$server = $_.server
Set-Adcomputer $server  -Description  $description
}
0
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 400 total points
ID: 40010772
Sorry? Adding the description to AD isn't part of this question, the title expressly states "locally".
Anyway, the necessary AD code is nothing more than
import-csv ComputerDescriptions.csv | % {
  Set-ADComputer $_.server  -Description  $_.description
}

Open in new window

No vars are needed here at all.
The way you use the CSV file it needs the two column headers Server and Description. If you want to combine the "local" and "AD" part:
Import-Module PSRemoteRegistry
$Key = "SYSTEM\CurrentControlSet\services\LanmanServer\Parameters\"

import-csv ComputerDescriptions.csv | % {
  Set-ADComputer $_.Server  -Description  $_.Description
  Set-RegString -Ping -ComputerName $_.Server -Hive 'LocalMachine' -Key $Key -Value 'srvcomment' -Data $_.Description
}

Open in new window

0
 

Author Comment

by:S T
ID: 40012968
Hi Qlemo,

This error pops up after running your code:

error
Please advice.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40014266
The error message tells that you did not import the PSRemoteRegistry module. This is part of the code I provided.
0
 

Author Comment

by:S T
ID: 40015938
Hi Qlemo,

What I did:
I installed and tested “Remote Registry PowerShell Module“ on my domain PC
http://archive.msdn.microsoft.com/PSRemoteRegistry

I saved your script below and named it “SetPCDescription.ps1”
Import-Module PSRemoteRegistry
$Key = "SYSTEM\CurrentControlSet\services\LanmanServer\Parameters\"

import-csv ComputerDescriptions.csv | % {
  Set-ADComputer $_.Server  -Description  $_.Description
  Set-RegString -Ping -ComputerName $_.Server -Hive 'LocalMachine' -Key $Key -Value 'srvcomment' -Data $_.Description
}

On my Domain PC, I saved SetPCDescription.ps1 and ComputerDescriptions.csv (with two column headers Server and Description) to c:\scripts\

From my Domain PC, I opened Powershell as Admin

I verified these:

get-service winrm
The value of the Status property in the output should be “Running”.

To configure Windows PowerShell for remoting, type the following command:
Enable-PSRemoting –force

I then ran this command:
RunAs /u:DOMAIN\DOMAIN ADMIN "powershell -file c:\scripts\SetPCDescription.ps1"

It asked me for my domain admin password which I entered.

Then another black DOS window popped up and closed very fast.

I then RDPied to a Server but it did not get it’s description.

Please advice.

Thank you for all your patience.

ST
0
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 400 total points
ID: 40016265
I might loose my patience soon.

I already told you in http:#a39993026 that WsMan / WinRM are not related to Remote Registry, so that stuff is superfluous to enable or test.

What you did last doesn't comply with http:#a40012968, so you changed your action again. Note that you cannot expect us to follow each sidewinding. Now you cannot see any error message, because you made it more complex as necessary.

It really isn't difficult. Start a PowerShell console with Admin privs - with RunAs, or via Shift-RightClick on the PS menu entry, or however you want to start it. Then start the script within that console.
If that works. we can talk about different, automated methods to run the script, but I don't think those to be necessary.
0
 

Author Closing Comment

by:S T
ID: 40016435
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question