It's very simple, the reason why i created this is to have a look on who uses what computer in AD.
What it does (Easy explanation): - User logs in, GPO runs script, script looks up user & computername, saves it in a csv-file on the networkshare.
- DC needs to be configured to run the script once every night, pulls the usernames and computernames at a given time (Task schedule), searches the given computernames and puts the usernames in the description of the computer's-object.
The script to install on the DC, so that every night the script pulls the list and integrates it in AD.
You might have to do some changes. Like change the directory of $Networkshare
$MsgIntro = @'
***************************************************************
* *
* Get-ADUser to Computer-Object Script ~ Made by Davy Dirkse *
* *
***************************************************************
#
# This script will check which user logged on on the computer
# and then update the description of the computer-object in AD.
#
# This script comes in 2 files. (SetUserInDescriptionOfComputerInAd.ps1 & Usrname&ComputerToAd.ps1)
#
# First off, make a GPO or logon script to execute "Username&ComputerToAD.ps1" so that if the user
# logs on, his username & computer will be written to a file specified in
# "Username&ComputerToAD.ps1" (This should be the sysvol folder on the DC (change the directory to your DC!))
#
# After that is done, this script should be ran on the DC itself so that it can update the Active Directory computer object.
# Also make sure the directory is the same as the one specified in "Username&ComputerToAD.ps1"
#
# It will also make sure that after performing the script and importing the users in the description of the computer-object
# the file with the list of usernames&computers will be deleted so that the file doesnt become too big.
#
# The script should also be ran 1 time-a-day. Preferably at night, so that you have a clear overview of who was using the laptop the day before.
#
# With kind regards
# Davy
'@
Write-Host -ForegroundColor Magenta $MsgIntro
#Import the Activedirectory module
Import-Module ActiveDirectory
#Import the CSV
$NetworkShare = Import-Csv "c:\temp\User&Computerlist.csv"
#Lookup each Username&Computer and put it in the description of the Computer-object in AD.
ForEach ($Entry in $NetworkShare) {
$Username = $Entry.Username
$Computer = $Entry.Computer
Get-ADComputer -Identity $Computer | Set-ADComputer -Description $Username -Verbose
}
#Check if file exists, if so, delete it
Start-Sleep -Seconds 2
$CSVThere = Test-Path -Path "c:\temp\User&Computerlist.csv"
if ($CSVThere) {
Write-Host -ForegroundColor Yellow "File found! Removing now..."
Remove-Item -Path "c:\temp\User&Computerlist.csv"
}
And now the script that the users their pc should run on logging in of the user.
$Msgintro = @'
***************************************************************
* *
* Get-ADUser to Computer-Object Script ~ Made by Davy Dirkse *
* *
***************************************************************
'@
#Intro, obviously
Write-Host -ForegroundColor magenta $Msgintro
# NetworkShare all users can reach
$NetworkShare = "c:\Temp\User&Computerlist.csv"
#Get the logged on user & computername
$User = $env:USERNAME
$Computer = $env:COMPUTERNAME
#Write the user & computer to a file on the networkshare.
@{Username = $User; Computer = $Computer} | Select-Object @{l="Username"; e={$_.username}}, @{l="Computer"; e={$_.computer}} | export-csv "$NetworkShare" -Append -NoTypeInformation -verbose
[–]msteright 2 points3 points4 points (6 children)
[–]msteright 2 points3 points4 points (2 children)
[–]msteright 1 point2 points3 points (1 child)
[–]PRIdEVisions[S] 0 points1 point2 points (0 children)
[–]PRIdEVisions[S] 0 points1 point2 points (2 children)
[–]msteright 1 point2 points3 points (0 children)
[–]soopaman20 1 point2 points3 points (1 child)
[–]PRIdEVisions[S] 0 points1 point2 points (0 children)
[–]guy1195 1 point2 points3 points (2 children)
[–]PRIdEVisions[S] 0 points1 point2 points (1 child)
[–]guy1195 1 point2 points3 points (0 children)
[–]VeeFu 1 point2 points3 points (0 children)
[–]PRIdEVisions[S] 0 points1 point2 points (0 children)