【发布时间】:2014-05-09 02:58:13
【问题描述】:
我正在尝试创建一个函数,然后在将它传递给 Invoke-Command -scriptBlock 时调用该函数。但是,当我运行它时,它说它无法识别该功能
Function Feature
{
# Install Features
Add-WindowsFeature as-dist-transaction,as-was-support , fs-fileserver, web-server,web-webserver,web-app-dev,web-dav-publishing,web-http-redirect,web-http-tracing,web-lgcy-mgmt-console,web-metabase, web-mgmt-compat,web-mgmt-service,web-scripting-tools,web-dyn-compression,web-windows-auth,net-http-activation,net-non-http-activ, rsat-web-server, telnet-client, SNMP-Service
# Agent Contact
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\RFC1156Agent" /v sysContact /t REG_SZ /d "Production Team" /f
# Agent Location
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\RFC1156Agent" /v sysLocation /t REG_SZ /d "Pleasant Hill" /f
# Agent Services (all)
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\RFC1156Agent" /v sysServices /t REG_DWORD /d 79 /f
# Community Name
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\TrapConfiguration\!snmp%AM!" /v 1 /t REG_SZ /d "amprdsys04.assetmark.com" /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\SNMP\Parameters\ValidCommunities" /v "!snmp%AM!" /t REG_DWORD /d 4 /f
# Restart the SNMP Service
restart-service snmp
# Configure the Windows Management Instrumentation service recovery time
sc.exe failure Winmgmt reset= 86400 actions= restart/60000/restart/60000/none/60000
# Install Other Required Features
D:\Install\ASPNetMVC3\AspNetMVC3Setup.exe /q
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe /i
# end
}
Invoke-Command -ComputerName Computer123-ScriptBlock {Feature}
【问题讨论】:
-
为了让它更像 PowerShell,您可以将所有
reg add命令替换为Set-Itemproperty。
标签: powershell