System Restore Script - Output to Custom Field

Hi all

I am trying to create a script with a nice table that will display in a custom field - the table will list System Restore Points.

My Custom Field currently looks like this:
image

I would like it to display this information:
image

This is the script so far:

#####################################################################################
Import-Module $env:SyncroModule
$logFile = "C:\temp"
$SR = Get-ComputerRestorePoint
$LogDate = get-date -format “d-MM-yy”

Start-Transcript -Path C:\temp$LogDate-SystemRestore.log -append
Get-ComputerRestorePoint | Format-Table SequenceNumber, @{Label=“Date”; Expression={$.ConvertToDateTime($.CreationTime)}}, Description -Auto ;
stop-transcript

Set-Asset-Field -Name “SystemRestoreList” -Value $SR
#####################################################################################

I think I need to move $SR =

Any suggestions?

Thanks

Import-Module $env:SyncroModule
$output = Get-ComputerRestorePoint | Sort-Object -Property SequenceNumber -Descending | Format-Table @{Label=“Number”; Expression={$_.SequenceNumber};align='left'}, @{Label=“Date”; Expression={$_.ConvertToDateTime($_.CreationTime)};align='left'}, @{Label=“Description”; Expression={$_.Description};align='left'}
Set-Asset-Field -Name "SystemRestoreLog" -Value $output

Untested - but I think is what you wanted?

Negative :frowning:

Custom Field:

image

That would be an issue with the commend it self - for example, that command only works on Windows 10 and above I believe. Either you are running the commend on something older than Windows 10 or that the support PowerShell version doesnt support the function.

Sorry, that was just base off the code you gave me without proper knowledge that it was going to be running on an older operating system. I would have to dig a little to see what would work for Windows below 10 to get the system restore point information.

Nope, its Windows 10 latest build.

Can to get me the powershell version?

I believe powershell-5.1 is the required version to use that command.

Latest by the looks of it.

Let me try on a nother machine.

Tried on anothr machine

Here is the script output:

image

Custom Field:
image

Getting closer then:) more than likely it sees it as a object still then - just need to convert the object to string… try

$output = Get-ComputerRestorePoint | Sort-Object -Property SequenceNumber -Descending | Format-Table @{Label=“Number”; Expression={$_.SequenceNumber};align='left'}, @{Label=“Date”; Expression={$_.ConvertToDateTime($_.CreationTime)};align='left'}, @{Label=“Description”; Expression={$_.Description};align='left'} | Out-String

Your the man!!

image

Thanks for that!

You are welcome - you might need to play with it a bit - but figure that would get you at least on the right road.

1 Like

Absolutely thanks man! Its the simplest way to do it as well which helps. There are so many ways but it needs to be not complicated.
Nice & clean.

What happens for example if Expression= has a space… Mapepd Drives for instance. Its Remote Path and Local Path.

How do you pass those as expressions as it errors out due to the Space

Just put it in qoutes, for example:

$_.'Local Path'

or

$_.'Remote Path'
1 Like

Ahhh I was using “”
Let me try that.

Single quotes does not evaluate expressions like $variable in the string. Double quotes does.

1 Like