Skip to content

Add-Type 'DateTime' not recognized #206

@Rtw915

Description

@Rtw915

I think it is a bug

I have a script that run fine in ISE or the console but would not run in PRTG.

in PRTG it would output this in the log file:


(1) :     using System;
At C:\Program Files\WindowsPowerShell\Modules\PoshRSJob\1.7.4.4\PoshRSJob.psm1:51 char:5
+     Add-Type @"
+     ~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerErro 
   r) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
WARNING: (0) : No source files specified

(1) :     using System;
Add-Type : Cannot add type. Compilation errors occurred.
At C:\Program Files\WindowsPowerShell\Modules\PoshRSJob\1.7.4.4\PoshRSJob.psm1:51 char:5
+     Add-Type @"
+     ~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-Type], InvalidOperationException
    + FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
 
Unable to find type [RSJob].
At C:\Program Files\WindowsPowerShell\Modules\PoshRSJob\1.7.4.4\Public\Get-RSJob.ps1:72 char:9
+         [RSJob[]]$Job,
+         ~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (RSJob:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound
 
Unable to find type [RSJob].
At C:\Program Files\WindowsPowerShell\Modules\PoshRSJob\1.7.4.4\Public\Get-RSJob.ps1:72 char:9
+         [RSJob[]]$Job,
+         ~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (RSJob:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

After searching for the issue I found this:
https://social.technet.microsoft.com/Forums/windows/en-US/c8467128-ab64-4920-8697-3cc76e901568/addtype-usage?forum=winserverpowershell

In PoshRSJob.psm1 I changed line 72 from:

public DateTime LastActivity = DateTime.MinValue;
to
public System.DateTime LastActivity = System.DateTime.MinValue;

It now appears to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions