Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems

Using puppet to set Windows Computer Description

Posted by Admin • Monday, May 18. 2020 • Category: DevOps

My company's security department decided to assign Antivirus exclusion policies based on the value of the windows computer description. That means that I need to set computer descriptions ( net config server /srvcomment:"new description" ) to the same value on a whole bunch of windows machines. Doing that by hand is unappealing, and I already have puppet, so here is a simple solution:


# Gets computer decscription from 'net config server'
Facter.add("win_computer_description") do
  setcode do
    output = `net config server`
    output.split(/\n/).find{|it| it.start_with?('Server Comment') }.gsub(/Server Comment[\s]*/,'')


class MY_CLASS(
  $computer_description = 'Some-new-description',
) {
  if ($win_computer_description != $computer_description) {
    exec { 'Set computer description':
      path => ["C:\\windows\\system32"],
      command => "net config server /SRVCOMMENT:\"${computer_description}\"",