May 24, 2017, 02:46:40 AM
Welcome, Guest. Please login or register.

"Have you tried turning it off and then on again?"

Author Topic: Powershell Change Computer description request  (Read 2127 times)

Offline em3rgency

  • Elite
  • *****
  • Posts: 744
  • Internets: +36/-3
  • OSWP SQLi N+
    • Security Research
Powershell Change Computer description request
« on: May 19, 2015, 11:42:20 AM »
Hey everyone,

I appreciate you taking the time to read this. I need help editing this script to be able to handle a list of servers from a file ( serverlist.txt). The problem is that It only handles one server at a time. Can anyone help?

This is a VBS script that will be run in WINDOWS 7

Dim strDescription, strComputer, reg, objRegistry
Dim ret, msg, ValueName

Const HKLM = &H80000002
strComputer = inputbox("Input a computer name.")

if strComputer = "" then wscript.quit

on error resume next

Set reg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

if err.number <> 0 then
  msgbox "There was an error while attempting to connect to " & strComputer & "'s WMI database.  Is the computer powered on?  If so, there may be an issue with your permissions.",16,"Error connecting to '" & strComputer & "'"
  wscript.quit 
end if

on error goto 0

Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2").ExecQuery("Select Description FROM Win32_OperatingSystem")


For Each object In objRegistry
   strDescription = object.Description
Next

value = inputbox("Input a computer description for '" & strComputer & "':","Enter a new description",strDescription)

If value = strDescription then wscript.quit

key = "SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
ValueName = "srvcomment"

If Len(Value) > 48 Then Value = Left(Value, 48)
ret = reg.SetStringValue(HKLM, key, ValueName, value)

if ret <> 0 then msgbox "Remote update failed."
« Last Edit: May 19, 2015, 12:05:29 PM by em3rgency »
Website: http://www.em3rgency.com

My other computer is your computer.

Offline em3rgency

  • Elite
  • *****
  • Posts: 744
  • Internets: +36/-3
  • OSWP SQLi N+
    • Security Research
Re: Powershell Change Computer description request
« Reply #1 on: May 19, 2015, 11:43:10 AM »
Also If it can push all the computer names and descriptions changes to a .csv file or something to search. That would be tits.
Website: http://www.em3rgency.com

My other computer is your computer.

Offline 0E 800

  • If something can corrupt you, you're corrupted already.
  • Top Hat Member
  • Elite
  • ********
  • Posts: 961
  • Internets: +154/-0
  • • тнε ιηтεяηεт ιs мү яεcүcℓε-вιη •
Re: Powershell Change Computer description request
« Reply #2 on: May 19, 2015, 11:56:51 AM »
Code: [Select]
$server_names = Get-Content "C:\Servers_list.txt"
Foreach ($server in $server_names){
your code here
}

Put ip# in Servers_list.txt like this:
192.168.0.1
192.168.0.2
etc.

What does your script do? Change the computers description?

Alot of your code is confusing to me, will all the checks and error messages. I would just find the actually commands. I tried to guess how it would look:

Code: [Select]
Dim strDescription, strComputer, reg, objRegistry
Dim ret, msg, ValueName

Const HKLM = &H80000002
$server_names = Get-Content "C:\Servers_list.txt"

#if strComputer = "" then wscript.quit

#on error resume next

Foreach ($server in $server_names){

Set reg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

if err.number <> 0 then
  msgbox "There was an error while attempting to connect to " & strComputer & "'s WMI database.  Is the computer powered on?  If so, there may be an issue with your permissions.",16,"Error connecting to '" & strComputer & "'"
  wscript.quit 
end if

on error goto 0

Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2").ExecQuery("Select Description FROM Win32_OperatingSystem")


For Each object In objRegistry
   strDescription = object.Description
Next

value = inputbox("Input a computer description for '" & strComputer & "':","Enter a new description",strDescription)

If value = strDescription then wscript.quit

key = "SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
ValueName = "srvcomment"

If Len(Value) > 48 Then Value = Left(Value, 48)
ret = reg.SetStringValue(HKLM, key, ValueName, value)

if ret <> 0 then msgbox "Remote update failed."
}

Good luck.
« Last Edit: May 19, 2015, 12:09:39 PM by 0E 800 »
"He who passes not his days in the realm of dreams is the slave of the days."

Offline em3rgency

  • Elite
  • *****
  • Posts: 744
  • Internets: +36/-3
  • OSWP SQLi N+
    • Security Research
Re: Powershell Change Computer description request
« Reply #3 on: May 19, 2015, 12:04:59 PM »
Thanks for taking a look

The script changes the computer description. Its in .vbs. it will be run in windows

I only know bash so I am SOL on this.

Right now it only handles 1 computer at a time. I just need it to handle a list of a LOT of servers in windows

I cant find anything on the net that handles a serverlist.. for changing windows computer descriptions..  >:(
« Last Edit: May 19, 2015, 12:09:05 PM by em3rgency »
Website: http://www.em3rgency.com

My other computer is your computer.

Offline 0E 800

  • If something can corrupt you, you're corrupted already.
  • Top Hat Member
  • Elite
  • ********
  • Posts: 961
  • Internets: +154/-0
  • • тнε ιηтεяηεт ιs мү яεcүcℓε-вιη •
Re: Powershell Change Computer description request
« Reply #4 on: May 19, 2015, 12:13:03 PM »
Haha, didnt realize it was a VB script. Thought it was powershell. Shows how tired I am.

This link should put you on right track.

http://portal.sivarajan.com/2011/08/udpate-comptuer-descriptionpowershell.html

Btw- I have a nifty powershell script that will create a Excel spreadsheet with all device information (cpu, memory, hdd, etc) in case you want.
"He who passes not his days in the realm of dreams is the slave of the days."

Offline TeamVega

  • Enthusiast
  • **
  • Posts: 82
  • Internets: +20/-0
Re: Powershell Change Computer description request
« Reply #5 on: May 19, 2015, 10:20:35 PM »
@ OE 800
can you please share so we can check it out?

Thanks

Offline 0E 800

  • If something can corrupt you, you're corrupted already.
  • Top Hat Member
  • Elite
  • ********
  • Posts: 961
  • Internets: +154/-0
  • • тнε ιηтεяηεт ιs мү яεcүcℓε-вιη •
Re: Powershell Change Computer description request
« Reply #6 on: May 20, 2015, 09:59:15 AM »
I could paste the code, but best just to give props to the original author.

https://gallery.technet.microsoft.com/scriptcenter/PowerShell-OS-Inventory-cc4a1664

Let me know if you need help running it.
"He who passes not his days in the realm of dreams is the slave of the days."

Offline TeamVega

  • Enthusiast
  • **
  • Posts: 82
  • Internets: +20/-0
Re: Powershell Change Computer description request
« Reply #7 on: May 21, 2015, 12:37:09 AM »
Thanks OE 800
Much appreciated.

Offline em3rgency

  • Elite
  • *****
  • Posts: 744
  • Internets: +36/-3
  • OSWP SQLi N+
    • Security Research
Re: Powershell Change Computer description request
« Reply #8 on: May 21, 2015, 08:15:59 AM »
Thanks again,

Getting closer, This script actually updates Active Directory computer descriptions. I got it figured out and it works. However I cannot get the remote local comptuer description to update. Anyone know powershell enough to get the "Update Computers Description On remote local machine" script to work? The follow below script are the commands I need to use, I just cant figure out how to get it working for the Computers.csv file instead of a single machine.

# Update Computers Description On remote local machine -- Main script I need to work
Import-CSV "C:\Temp\powershell\Computers.csv" | % {
$Computer = $_.ComputerName
$Desc = $_.Description
#Get-WmiObject -class Win32_OperatingSystem $Computer -Description $Desc
}

# Udpate a single Computers Description On remote local machine - Working script for a single machine
$OSValues = Get-WmiObject -class Win32_OperatingSystem -computername "dwn00223"
$OSValues.Description = "Changed to new value"
$OSValues.put()




# Update Computers Description In Active Directory -- WORKING
Import-CSV "C:\Temp\powershell\Computers.csv" | % {
$Computer = $_.ComputerName
$Desc = $_.Description
Set-ADComputer $Computer -Description $Desc
}
Website: http://www.em3rgency.com

My other computer is your computer.

Offline 0E 800

  • If something can corrupt you, you're corrupted already.
  • Top Hat Member
  • Elite
  • ********
  • Posts: 961
  • Internets: +154/-0
  • • тнε ιηтεяηεт ιs мү яεcүcℓε-вιη •
"He who passes not his days in the realm of dreams is the slave of the days."

Offline em3rgency

  • Elite
  • *****
  • Posts: 744
  • Internets: +36/-3
  • OSWP SQLi N+
    • Security Research
Re: Powershell Change Computer description request
« Reply #10 on: May 21, 2015, 12:25:24 PM »
Working power-shell script for updating local machine descriptions

# Update Computers Description On remote local machine
Import-CSV "C:\Temp\powershell\Computers.csv" | % {
$Computer = $_.ComputerName
$Desc = $_.Description
#Get-WmiObject -class Win32_OperatingSystem $Computer -Description $Desc

$OSValues = Get-WmiObject -class Win32_OperatingSystem -computername $Computer
$OSValues.Description = $Desc
$OSValues.put()

}
Website: http://www.em3rgency.com

My other computer is your computer.

Offline em3rgency

  • Elite
  • *****
  • Posts: 744
  • Internets: +36/-3
  • OSWP SQLi N+
    • Security Research
Re: Powershell Change Computer description request
« Reply #11 on: May 24, 2015, 06:46:33 PM »
Powershell is an amazing skill to learn for sys admins. Along with security training, which none in corporate america has, is a great skill. Being able to successfully identify security risks on your team, will make you stand out no doubt.
Website: http://www.em3rgency.com

My other computer is your computer.