• PowerTip of the DayCreate Remoting Solutions


    原文地址:http://powershell.com/cs/blogs/tips/archive/2010/06/10/create-remoting-solutions.aspx

    原文:

    Whenever you use WMI (Get-WMIObject) to retrieve information, it's a snap to turn a local solution into a remotable solution. You can just add the parameter -Computername to Get-WMIObject.

    In a previous tip, you learned how to examine physical memory. Here's a wrapper function that makes this code run locally as well as remotely (provided that you have sufficient access privileges):

    function Get-Memory($computername = 'localhost') {
    $memorytype = "Unknown", "Other", "DRAM", "Synchronous DRAM", "Cache DRAM",
    "EDO", "EDRAM", "VRAM", "SRAM", "RAM", "ROM", "Flash", "EEPROM", "FEPROM",
    "EPROM", "CDRAM", "3DRAM", "SDRAM", "SGRAM", "RDRAM", "DDR", "DDR-2"
    $formfactor = "Unknown", "Other", "SIP", "DIP", "ZIP", "SOJ", "Proprietary",
    "SIMM", "DIMM", "TSOP", "PGA", "RIMM", "SODIMM", "SRIMM", "SMD", "SSMP",
    "QFP", "TQFP", "SOIC", "LCC", "PLCC", "BGA", "FPBGA", "LGA"
    $col1 = @{Name='Size (GB)'; Expression={ $_.Capacity/1GB } }
    $col2 = @{Name='Form Factor'; Expression={$formfactor[$_.FormFactor]} }
    $col3 = @{Name='Memory Type'; Expression={ $memorytype[$_.MemoryType] } }
    $col4 = @{Name='ComputerName'; Expression=[Scriptblock]::Create("'$computername'")}
    Get-WmiObject Win32_PhysicalMemory -computername $computername |
    Select-Object BankLabel, $col1, $col2, $col3, $col4
    }

     

    翻译:

    无论什么时候通过WMI(Get-WMIObject)来处理信息,把 本地的方案变成远程执行的方案是很简单的。只需要在Get-WMIObject中加一个参数:-Computername.

    在上一篇中介绍了如何查看物理内存信息,以下方法是对其进一步封装,使其能在本地运行远程的代码(需要确定在目标机器上有足够的权限)

    function Get-Memory($computername = 'localhost') {
    $memorytype = "Unknown", "Other", "DRAM", "Synchronous DRAM", "Cache DRAM",
    "EDO", "EDRAM", "VRAM", "SRAM", "RAM", "ROM", "Flash", "EEPROM", "FEPROM",
    "EPROM", "CDRAM", "3DRAM", "SDRAM", "SGRAM", "RDRAM", "DDR", "DDR-2"
    $formfactor = "Unknown", "Other", "SIP", "DIP", "ZIP", "SOJ", "Proprietary",
    "SIMM", "DIMM", "TSOP", "PGA", "RIMM", "SODIMM", "SRIMM", "SMD", "SSMP",
    "QFP", "TQFP", "SOIC", "LCC", "PLCC", "BGA", "FPBGA", "LGA"
    $col1 = @{Name='Size (GB)'; Expression={ $_.Capacity/1GB } }
    $col2 = @{Name='Form Factor'; Expression={$formfactor[$_.FormFactor]} }
    $col3 = @{Name='Memory Type'; Expression={ $memorytype[$_.MemoryType] } }
    $col4 = @{Name='ComputerName'; Expression=[Scriptblock]::Create("'$computername'")}
    Get-WmiObject Win32_PhysicalMemory -computername $computername |
    Select-Object BankLabel, $col1, $col2, $col3, $col4
    }

     

     

    笔记:

    复习get-wmiobject

    又一种在函数中声明参数的方法。

  • 相关阅读:
    Windows 软件推荐大全【all】
    网络基础之IP地址和子网掩码
    Windows 常识大全【all】
    FinalShell使用---Xshell的良心国产软件
    雷军语录:写程序有写诗一样的感觉
    Proxyee-down的下载与安装教程
    QPointer,QSharedPointer,QWeakPointer的区别
    Android Auto开发初探
    车载摄像头 原像 镜像
    Bluetooth协议栈学习之SDP
  • 原文地址:https://www.cnblogs.com/aspnetx/p/1756127.html
Copyright © 2020-2023  润新知