-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadReportDescription.sh
More file actions
25 lines (20 loc) · 1.07 KB
/
adReportDescription.sh
File metadata and controls
25 lines (20 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# Gather information about the computer
adComputerName="$(dsconfigad -show | grep "Computer Account" | awk '{print $4}')"
adDomain="$(dsconfigad -show | grep "Active Directory Domain" | awk '{print $5}')"
adString="$(dscl /Search read /Computers/$adComputerName | grep dsAttrTypeNative:distinguishedName | cut -c 37-)"
username="$(id -F)"
timestamp="$(date +'%d-%m-%Y - %H:%M')"
hardwareModel="$(sysctl hw.model | cut -c 11-)"
serieNummer="$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformSerialNumber/{print $(NF-1)}')"
systemVersion="$(sw_vers | grep ProductVersion | cut -c 17-)"
# Creates a temporary with the gathered data, correctly formatted for AD
echo "dn: $adString" > /tmp/adReport
echo "changetype: modify" >> /tmp/adReport
echo "replace: description" >> /tmp/adReport
echo "description: $username - Logon: $timestamp / Model: $hardwareModel / Serial: $serieNummer / OS: MacOS $systemVersion" >> /tmp/adReport
# Write data back to AD
ldapmodify -h "$adDomain" -f /tmp/adReport
# Remove the temporary file with the gathered data
rm /tmp/adReport
exit 0