Powershell脚本

时间:2012-05-14 10:31:22

标签: powershell batch-file

我有类似的问题,我想在Win 7上安装Ciscoemail,但它根本没有用。我已经通过组策略使用此脚本在Win XP上成功安装了

md c:\ciscoemail

if not exist c:\ciscoemail\CiscoEmailSecurity_7-2-0-039.exe copy \\Domain Name\cisco\CiscoEmailSecurity_7-2-0-039.exe c:\ciscoemail /Y
if not exist c:\ciscoemail\response_file.iss copy \\Domain Name\cisco\response_file.iss c:\ciscoemail /Y
del c:\ciscoemail\setup.log /f /q

if not exist C:\PROGRA~2\Cisco\CISCOI~1\CISCOE~1.DLL c:\ciscoemail\CiscoEmailSecurity_7-2-0-039.exe /s /v /qn /f1"c:\ciscoemail\response_file.iss"

有人可以协助将代码转换为Powershell代码。 简单的步骤是:

  1. 将目录设为本地c盘。

  2. 检查本地c盘上是否存在ciscoemail。

  3. 创建文件夹(如果该文件夹不存在)并将ciscoemail \ CiscoEmailSecurity_7-2-0-039.exe和ciscoemail \ response_file.iss复制到c盘

  4. .exe(安装文件)

1 个答案:

答案 0 :(得分:0)

基本翻译:

# In PowerShell, md is an alias to mkdir which 
# is a function for creating folders
$folder = md c:\ciscoemail

# copy is an alias for Copy-Item
if( -not(Test-Path -Path c:\ciscoemail\CiscoEmailSecurity_7-2-0-039.exe))
{
    copy -Path \\Domain Name\cisco\CiscoEmailSecurity_7-2-0-039.exe -Destination $folder.FullName
}

if( -not(Test-Path -Path c:\ciscoemail\response_file.iss))
{
    copy -Path \\Domain Name\cisco\response_file.iss -Destination $folder.FullName
}

if( Test-Path -Path c:\ciscoemail\setup.log )
{
    # del is an alias to Remove-Item
    del -Path c:\ciscoemail\setup.log -ErrorAction SilentlyContinue -Force
}        

if( -not(Test-Path -Path "C:\PROGRA~2\Cisco\CISCOI~1\CISCOE~1.DLL"))
{
    c:\ciscoemail\CiscoEmailSecurity_7-2-0-039.exe /s /v /qn /f1"c:\ciscoemail\response_file.iss"
}