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

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
S TAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
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
 
Schnell SolutionsConnect With a Mentor Systems Infrastructure EngineerCommented:
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
 
becraigCommented:
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
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
S TAuthor Commented:
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
 
becraigCommented:
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
 
becraigCommented:
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
 
Darrell PorterEnterprise Business Process ArchitectCommented:
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
 
Schnell SolutionsSystems Infrastructure EngineerCommented:
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
 
S TAuthor Commented:
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
 
S TAuthor Commented:
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
 
Darrell PorterEnterprise Business Process ArchitectCommented:
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
 
S TAuthor Commented:
Hi WalkaboutTigger,

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

Please advice.
0
 
Darrell PorterConnect With a Mentor Enterprise Business Process ArchitectCommented:
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
 
S TAuthor Commented:
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
 
S TAuthor Commented:
Hi WalkaboutTigger,

I opened Windows PowerShell 64 bit as administrator

Then pasted your script.

But I get this error.ErrorPlease advice.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Remove the } in front of Get-Module - it does not belong there.
0
 
S TAuthor Commented:
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
 
Darrell PorterEnterprise Business Process ArchitectCommented:
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
 
S TAuthor Commented:
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
 
S TAuthor Commented:
Hi Qlemo,

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

Thx.
ek
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Doesn't matter, as long as the PsRemoting module is availablr locally.
0
 
S TAuthor Commented:
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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
 
S TAuthor Commented:
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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
 
S TAuthor Commented:
Thans Qlemo. Will keep trying next week and offer points.
0
 
S TAuthor Commented:
I've requested that this question be deleted for the following reason:

Solution does not work to my need.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
 
S TAuthor Commented:
Some answers have helped. Please do not delete this question.
0
 
S TAuthor Commented:
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
 
S TAuthor Commented:
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
 
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
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
 
S TAuthor Commented:
Hi Qlemo,

This error pops up after running your code:

error
Please advice.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The error message tells that you did not import the PSRemoteRegistry module. This is part of the code I provided.
0
 
S TAuthor Commented:
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
 
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
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
 
S TAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.