I am attempting to get a list of Change requests that meet a specific criteria using the following code:
# Convert to UTC Date time
$Date = (get-date);
$UTCDate = $Date.ToUniversalTime();
import-module smlets;
$statusCompletedId = (Get-SCSMEnumeration ChangeStatusEnum.Completed$).Id
$7DaysOld = (get-date).addhours(-1);
Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ChangeRequest$) | where{$_.lastmodified -lt $7DaysOld -AND $_.CreatedDate -gt '2010-11-08' -AND $_.Status -like $statusCompletedID}|Format-Table DisplayName, LastModified, CreatedDate, Status;
In listing all the CRs I have confirmed there are CRs that meet my criteria. But when I run the above code, nothing is returned.
I have tried modifying the code at http://myitforum.com/myitforumwp/2011/11/14/scsm-auto-closing-a-change-request-dual-criteria/?utm_source=rss&utm_medium=rss&utm_campaign=scsm-auto-closing-a-change-request-dual-criteria
as follows:
# Convert to UTC Date time
$Date = (get-date);
$UTCDate = $Date.ToUniversalTime();
import-module smlets;
$7DaysOld = (get-date).addhours(-1);
$class = "Get-SCSMClass -name System.WorkItem.ChangeRequest$"
$statusCompletedId = (Get-SCSMEnumeration ChangeStatusEnum.Completed$).Id
$critString = "Status = ‘$statusCompletedId’ AND LastModified < '$7daysOld'"
$criteriaType = "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"
$criteria = New-Object $criteriaType $critString, $class
Get-SCSMObject -Criteria $criteria
remove-module smlets;
But get the following error:
New-Object : Cannot find an overload for "EnterpriseManagementObjectCriteria" and the argument count: "2".
At C:\users\leslier_buchanan\Documents\scripts\CRs.ps1:11 char:23
+ $criteria = New-Object <<<< $criteriaType $critString, $class
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Get-SCSMObject : Cannot bind argument to parameter 'Criteria' because it is null.
At C:\users\leslier_buchanan\Documents\scripts\CRs.ps1:12 char:25
+ Get-SCSMObject -Criteria <<<< $criteria
+ CategoryInfo : InvalidData: (:) [Get-SCSMObject], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,SMLets.GetSMObjectCommand
Any help would be greatly appreciated