Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Guys,
PowerShell script executed with PowerShell version 2.0 and onwards gets executed successfully. But the same script when ran on powershell version 1.0 (on other system having powershell version 1.0) gets failed. So is there any other way to execute the same script on powershell v1.0 as well

Here is my script for exchange server backup:
#
#.SYNOPSIS
#Checks the backup timestamps for the servers
#and alerts if a database hasn't been backed up
#in the last 1 day
#
#.EXAMPLE
#.\Check-DatabaseBackups.ps1
#

#...................................
# Variables
#...................................
#$ErrorActionPreference = "SilentlyContinue"
$ErrorActionPreference = "Continue"
$WarningPreference = "SilentlyContinue"
set-executionpolicy -executionpolicy unrestricted -force
Add-PSSnapin Microsoft.Exchange.Management.Powershell.admin
New-EventLog -LogName Application -Source "abcd"
$xyz = ""
$ago = 24
$now = [DateTime]::Now
$dbs = ""

#...................................
# Script
#...................................

#Get all Mailbox and Public Folder databases

$dbs = Get-MailboxDatabase -Status
$dbs = $dbs += Get-PublicFolderDatabase -Status

#Check each database for most recent backup
foreach ($db in $dbs)
{ if ($db) {
if (!$db.LastFullBackup -and !$db.LastIncrementalBackup){[int]$ago = 25}
elseif ( $db.LastFullBackup -lt $db.LastIncrementalBackup )
{
[int]$ago = ($now - $db.LastIncrementalBackup).TotalHours
$ago = "{0:N0}" -f $ago
}
elseif ( $db.LastIncrementalBackup -lt $db.LastFullBackup )
{
[int]$ago = ($now - $db.LastFullBackup).TotalHours
$ago = "{0:N0}" -f $ago
}

#If backup time stamp older than threshold set alert flag and create object for alerting
if ($ago -gt "24")
{
[string]$VarDName = $db.name
foreach( $name in $VarDName){$xyz = $xyz + $db.name + "`r`n" }
}
}
}

if ($ago -gt "24") {Write-EventLog -Logname Application -Source "abcd" -EntryType Information -EventId 1 -Message ([string]$xyz)}

#end

What I have tried:

I tried the same script on powershell version 2.0 ,3.0 ,4.0 but all worked well. Issue only occurs for powershell version 1.0
Posted
Updated 11-Mar-16 3:06am
v3
Comments
Richard MacCutchan 1-Mar-16 9:00am    
What must you do? Fixing the errors/incompatibilities would be a good starting point. But if you want help from this forum then please edit your question and add the proper and complete details.
CHill60 1-Mar-16 9:19am    
Use the Improve question link to post your script - or at least the part that fails.
It is highly likely that you are using one of the cmdlets introduced with V2.0
Member 12361678 14-Mar-16 2:27am    
yes i have updated my question now along with that i have inserted a powershell script as well. thank you

1 solution

You need to find out what's failing and then convert that code into something that works on an older PowerShell.

There is no "automatic" or "setting" you can use or change to magically get it to work. Your code is using some feature that was introduced with PowerShell 2.0 that isn't available in PowerShell 1.0. It's that simple.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900