关于PowerShell版本1.0的问题 [英] Issues on powershell version 1.0

查看:169
本文介绍了关于PowerShell版本1.0的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

使用PowerShell 2.0版及以后执行的PowerShell脚本成功执行。但是在powershell版本1.0(在其他具有powershell版本1.0的系统上)上运行时,相同的脚本会失败。那么有没有其他方法可以在powershell v1.0上执行相同的脚本



这是我的交换服务器备份脚本:



#.SYNOPSIS

#检查服务器的备份时间戳

#并在没有备份数据库的情况下发出警报

#在过去1天内



#.EXAMPLE

#..\\Check-DatabaseBackups.ps1





#........................ ...........

#变量

#.................... ...............

#$ ErrorActionPreference =SilentlyContinue

$ ErrorActionPreference =继续

$ WarningPreference =SilentlyContinue

set-executionpolicy -executionpolicy unrestricted -force

Add-PSSnapin Microsoft.Exchange.Management.Powershell.admin

New-EventLog -LogName应用程序-Sourceabcd

$ xyz =

$前= 24

$ now = [ DateTime] ::现在

$ dbs =



#.............................. .....

#剧本

#.......................... .........



#获取所有邮箱和公用文件夹数据库



$ dbs = Get-MailboxDatabase -Status

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



#查看最近的每个数据库备份

foreach($ db in $ dbs)

{if($ db){

if(!$ db.LastFullBackup -and!) $ db.LastIncrementalBackup){[int] $前= 25}

elseif($ db.LastFullBackup -lt $ db.LastIncrementalBackup)

{

[int] $前=($ now - $ db.LastIncrementalBackup).TotalHours

$前={0:N0}-f $前一页

}

elseif($ db.LastIncrementalBackup -lt $ db.LastFullBackup)

{

[int] $ ago =($ now - $ db .LastFullBackup).TotalHours

$前={0:N0} - f $前一页

}



#If备份时间戳o lder比阈值设置警告标志并创建警告对象

if($ ago -gt24)

{

[string] $ VarDName = $ db.name

foreach($ varDName中的$ name){$ xyz = $ xyz + $ db.name +`r`n}

}

}

}



if($ ago -gt24){Write-EventLog -Logname Application -Sourceabcd-EntryType Information -EventId 1 -Message([string] $ xyz)}



#end



我尝试了什么:



我在powershell版本2.0,3.0,4.0上尝试了相同的脚本,但都工作了好。问题仅发生在powershell版本1.0

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

推荐答案

ErrorActionPreference =SilentlyContinue
ErrorActionPreference = "SilentlyContinue"


ErrorActionPreference =Continue
ErrorActionPreference = "Continue"


WarningPreference =SilentlyContinue

set-executionpolicy -executionpolicy unrestricted -force

Add-PSSnapin Microsoft.Exchange。 Management.Powershell.admin

New-EventLog -LogName Application -Sourceabcd
WarningPreference = "SilentlyContinue"
set-executionpolicy -executionpolicy unrestricted -force
Add-PSSnapin Microsoft.Exchange.Management.Powershell.admin
New-EventLog -LogName Application -Source "abcd"


这篇关于关于PowerShell版本1.0的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆