title: Setting a DateTime to $null/empty using PowerShell and the SCSM cmdlets
body: <p>I'm currently trying to sync additional attributes from the AD (Active Directory) for user objects in SCSM (System Center Service Manager) using a PowerShell script.</p>
  
  <p>The extension I wrote for this, includes an attribute for the expiration date of a AD user account (<code>DateTime</code> value, named <code>DateTimeAttribute</code> in the example) if the user account doesn't expire it should be empty/null.</p>
  
  <p>Using <code>Import-SCSMInstance</code>, which should be similar to a CSV import, it kind of works by passing <code>"null"</code> for the field. The problem is that <code>Import-SCSMInstance</code> seems to be quite unreliable and it doesn't offer any kind of information of why it works or doesn't work. Using <code>Update-SCSMClassInstance</code> seems to work a lot better but I can't figure out a way to clear the field using this and even using <code>[DateTime]::MinValue</code> will result in an error, stating that it's an invalid value.</p>
  
  <p>So would anyone have an idea on how to clear the value using <code>Update-SCSMClassInstance</code> or figure out why <code>Import-SCSMInstance</code> might or might not work?</p>
  
  <p>A simple example for this could look like the following:</p>
  
  <pre><code>$server = "&lt;ServerName&gt;"
  $extensionGuid = "&lt;GUID&gt;"
  Import-Module 'C:\Program Files\System Center 2012 R2\Service Manager\Powershell\System.Center.Service.Manager.psd1'
  
  New-SCManagementGroupConnection -ComputerName $server
  $extensionClass = Get-SCSMClass -Id $extensionGuid
  $scsmUserObject = Get-SCSMClassInstance -Class $extensionClass -Filter 'UserName -eq "&lt;User&gt;"'
  
  # Error
  $scsmUserObject.DateTimeAttribute = ""
  
  # Works but fails on Update-SCSMClassInstance
  $scsmUserObject.DateTimeAttribute = $null
  $scsmUserObject.DateTimeAttribute = [DateTime]::MinValue
  
  # Works
  $scsmUserObject.DateTimeAttribute = "01-01-1970"
  
  Update-SCSMClassInstance -Instance $scsmUserObject
  </code></pre>