Skip to content

Instantly share code, notes, and snippets.

@Stephanevg
Created September 1, 2016 14:55
Show Gist options
  • Save Stephanevg/1ce99ba13da2e183541d168e6863790f to your computer and use it in GitHub Desktop.
Save Stephanevg/1ce99ba13da2e183541d168e6863790f to your computer and use it in GitHub Desktop.
Class Computer {
[String]$Name
[String]$Type
[string]$Description
[string]$owner
[string]$Model
[int]$Reboots
[void]Reboot(){
$this.Reboots ++
}
Computer ([string]$Name){
if ($comp = Get-ADComputer -filter "name -eq '$Name'" -Properties * -ErrorAction SilentlyContinue){
$this.name =$Name
$this.Description = $Comp.Description
switch -wildcard ($comp.OperatingSystem){
('*Server*') {$this.Type = 'Server';Break}
('*workstation*') {$this.Type = 'Workstation'}
('*Laptop*') {$this.Type = 'Laptop';Break}
default { $this.Type = 'N/A'}
}
$this.owner = $comp.ManagedBy.Split(',')[0].replace('CN=','')
}else{
write-verbose "Could Not find $($this.name)"
}
}
Computer ([string]$Name, [String]$type,[string]$Description,[string]$owner,[String]$Model){
if (!($comp = Get-ADComputer -filter "name -eq '$Name'" -Properties name)){
if ($user = Get-ADUser -Filter "name -eq '$owner'"){
try{
New-ADComputer -Name $Name -Description $Description -ManagedBy $user -ErrorAction Stop
$this.Name = $Name
$this.Type = $type
$this.Description = $Description
$this.owner = $owner
}catch{
$_
}
}else{
write-warning "the user $($Owner) is not existing. Please verify and try again."
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment