Link to home
Start Free TrialLog in
Avatar of S T
S T

asked on

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
SOLUTION
Avatar of Ogandos
Ogandos
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of S T
S T

ASKER

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
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
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.
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.
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)
Avatar of S T

ASKER

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
Avatar of S T

ASKER

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 ?
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.
Avatar of S T

ASKER

Hi WalkaboutTigger,

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

Please advice.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of S T

ASKER

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
Avatar of S T

ASKER

Hi WalkaboutTigger,

I opened Windows PowerShell 64 bit as administrator

Then pasted your script.

But I get this error.User generated imagePlease advice.
Remove the } in front of Get-Module - it does not belong there.
Avatar of S T

ASKER

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of S T

ASKER

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,
Avatar of S T

ASKER

Hi Qlemo,

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

Thx.
ek
Doesn't matter, as long as the PsRemoting module is availablr locally.
Avatar of S T

ASKER

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.
User generated image
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.
Avatar of S T

ASKER

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:
User generated image
Thx.
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).
Avatar of S T

ASKER

Thans Qlemo. Will keep trying next week and offer points.
Avatar of S T

ASKER

I've requested that this question be deleted for the following reason:

Solution does not work to my need.
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.
Avatar of S T

ASKER

Some answers have helped. Please do not delete this question.
Avatar of S T

ASKER

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.
Avatar of S T

ASKER

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
}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of S T

ASKER

Hi Qlemo,

This error pops up after running your code:

User generated image
Please advice.
The error message tells that you did not import the PSRemoteRegistry module. This is part of the code I provided.
Avatar of S T

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial