2
2
2tele22018-12-05 10:14:31
linux
2tele2, 2018-12-05 10:14:31

How to correctly compose and use a script on GPO Server 2016 for users to write the "description" column of the computer in the OU Active Directory?

Good afternoon. I found a couple of scripts on the net that should write information about the current account used on the PC in the "description" column of the PC. But there is no way to get them to work.

On Error Resume Next
Dim adsinfo, ThisComp, oUser
Set adsinfo = CreateObject("adsysteminfo")
Set ThisComp = GetObject("LDAP://" & adsinfo.ComputerName)
Set oUser = GetObject("LDAP://" & adsinfo.UserName)
Thiscomp.put "description", "Logged on: " + oUser.cn + " " + CStr(Now)
ThisComp.Setinfo

On Error Resume Next
Dim adsinfo, ThisComp, oUser
Set adsinfo = CreateObject("adsysteminfo")
Set ThisComp = GetObject("LDAP://" & adsinfo.ComputerName)
Set oUser = GetObject("LDAP://" & adsinfo.UserName)
Thiscomp.put "description", ">> Logged off: " + oUser.cn + " " + CStr(Now)
ThisComp.Setinfo

another logo script
$USERDNSDOMAIN = $env:USERDNSDOMAIN
$COMPUTERNAME = $env:COMPUTERNAME
$ObjectHash = @{}
$ObjectHash.UserName = $env:USERNAME
$ObjectHash.UserDomain = $USERDNSDOMAIN
$ObjectHash.DateTime = "{0:dd.MM.yyyy-HH:mm:ss}" -f $(Get-Date)
$ObjectHash.Console = ([Boolean]$((query.exe SESSION | findstr.exe ">console") -match $env:USERNAME)).ToString()
$ObjectHash.PSversion = $Host.Version.Major.ToString()
$ObjectHash.MACAddress = (Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled = $True" | sort IPConnectionMetric | select -First 1).MACAddress
$ObjectHash.Memory = [string]$((Get-WmiObject CIM_PhysicalMemory | measure -Property Capacity -Sum).Sum/1GB)+"GB"
$ObjectHash.Processor = (Get-WmiObject Win32_Processor).Name
$ObjectHash.Battery = (Get-WmiObject Win32_Battery).DeviceID
$ObjectHash.BiosSN = (Get-WmiObject Win32_BIOS).SerialNumber
$ObjectHash.SystemManufacturer = (Get-WmiObject Win32_ComputerSystem).Manufacturer
$ObjectHash.SystemModel = (Get-WmiObject Win32_ComputerSystem).Model
 
$select = "UserName,UserDomain,DateTime,Console,PSversion,MACAddress,Memory,Processor,Battery,BiosSN,SystemManufacturer,SystemModel" -split ","
 
if([int]$Host.Version.Major -ge 3){
$Description = New-Object -TypeName PSCustomObject -Property $ObjectHash | select $select | ConvertTo-Json -Compress
} else {
    $Description = '{' + $(($select | % {'"'+"$($_)"+'"'+":"+'"'+"$($ObjectHash.$($_))"+'"'}) -join ",") + '}'
    }
 
if(!$Description){$Description = "Null"}
 
$DirectoryEntry = New-Object System.DirectoryServices.DirectoryEntry
$USERDNSDOMAIN_DN = $DirectoryEntry.distinguishedName
 
$Root = [ADSI]"LDAP://$USERDNSDOMAIN/$USERDNSDOMAIN_DN"
$Root
$SearchPC = new-object System.DirectoryServices.DirectorySearcher($Root)
$SearchPC.Filter = "(&(objectClass=computer)(Name=$COMPUTERNAME))"
$Computer = [ADSI]$($SearchPC.FindOne().Path)
$Computer.put("Description",$Description)
$Computer.put("info",$Description)
# Если на любом этапе в скрипте возникла ошибка, не изменяем описание компьютера в AD
if($error.count -ge 1){exit}
# Если не было ни одной ошибки, изменяем описание компьютера в AD
$Computer.SetInfo()
exit

Delegation set up, checked - the right users have the right to write a description. The necessary PC was allocated to a separate unit. A policy has been created in AD with the specified scripts when a user logs in and out. Scripts are located at E:\VBS

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Alexey Cheremisin, 2016-01-07
@leahch

And here, the reviewer - habrahabr.ru/company/xakep/blog/254119
Well, for harsh bearded programmers, there is emacs + org-mode :-)

P
Pan Propan, 2016-01-06
@mgis

I would also write myself. Essentially 1 employee model, and one arrival and departure time table

M
Mop9k89, 2016-01-07
@Mop9k89

As a matter of fact it is possible to make a DB on mysql and application for management.

S
Sp1DeR, 2016-01-07
@Sp1DeR

If suddenly anyone is interested, I found for myself www.kimai.org/download
Today we have been testing all day, so far we like it. The file needs to be processed quite a bit. And the best part is that it's a free solution :)

S
Statist Chikenson, 2016-01-14
@chikenson

primaERP

2
2tele2, 2019-04-02
@2tele2

It was necessary to decompose the scripts into the correct Logon and Logoff folders. For those that are created along with politics.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question