首页 | 邮件资讯 | 技术教程 | 解决方案 | 产品评测 | 邮件人才 | 邮件博客 | 邮件系统论坛 | 软件下载 | 邮件周刊 | 热点专题 | 工具
网络技术 | 操作系统 | 邮件系统 | 客户端 | 电子邮箱 | 反垃圾邮件 | 邮件安全 | 邮件营销 | 移动电邮 | 邮件软件下载 | 电子书下载

操作系统

Windows 9X | Linux&Uinx | Windows Server | 其它操作系统 | Vista | FreeBSD | Windows 7 |
首页 > 操作系统 > Windows Server > PowerShell 经典脚本贮藏室 > 正文

PowerShell 经典脚本贮藏室

出处:http://www.cnblogs.com/architect/ 作者:架构人生 时间:2010-3-24 14:59:02

由于最近对Powershell越来越喜欢,在空余时间,整理一下一些常用的经典例子分享给大家:

1. 活动目录,列出域信息

#===========================================
# 列出域信息
#===========================================
$strComputer = "." # zivsoft-lihua
$colItems = get-wmiobject -class "Win32_NTDomain" -namespace "root\CIMV2" `
-computername $strComputer
foreach ($objItem in $colItems) {
      write-host "Caption: " $objItem.Caption
      write-host "Client Site Name: " $objItem.ClientSiteName
      write-host "Creation Class Name: " $objItem.CreationClassName
      write-host "DC Site Name: " $objItem.DcSiteName
      write-host "Description: " $objItem.Description
      write-host "DNS Forest Name: " $objItem.DnsForestName
      write-host "Domain Controller Address: " $objItem.DomainControllerAddress
      write-host "Domain Controller Address Type: " $objItem.DomainControllerAddressType
      write-host "Domain Controller Name: " $objItem.DomainControllerName
      write-host "Domain GUID: " $objItem.DomainGuid
      write-host "Domain Name: " $objItem.DomainName
      write-host "DS Directory Service Flag: " $objItem.DSDirectoryServiceFlag
      write-host "DS DNS Controller Flag: " $objItem.DSDnsControllerFlag
      write-host "DS DNS Domain Flag: " $objItem.DSDnsDomainFlag
      write-host "DS DNS Forest Flag: " $objItem.DSDnsForestFlag
      write-host "DS Global Catalog Flag: " $objItem.DSGlobalCatalogFlag
      write-host "DS Kerberos Distribution Center Flag: " $objItem.DSKerberosDistributionCenterFlag
      write-host "DS Primary Domain Controller Flag: " $objItem.DSPrimaryDomainControllerFlag
      write-host "DS Time Service Flag: " $objItem.DSTimeServiceFlag
      write-host "DS Writable Flag: " $objItem.DSWritableFlag
      write-host "Installation Date: " $objItem.InstallDate
      write-host "Name: " $objItem.Name
      write-host "Name Format: " $objItem.NameFormat
      write-host "Primary Owner Contact: " $objItem.PrimaryOwnerContact
      write-host "Primary Owner Name: " $objItem.PrimaryOwnerName
      write-host "Roles: " $objItem.Roles
      write-host "Status: " $objItem.Status
      write-host
}

2 列出机器安装过的软件列表

#===================================
#列出安装列表
#===================================
$strComputer = "ziz-vmm-lihua" #可以是局域网远程机器
$colItems = get-wmiobject -class "Win32_Product" -namespace "root\CIMV2" `
-computername $strComputer
foreach ($objItem in $colItems) {
      write-host "Caption: " $objItem.Caption
      write-host "Description: " $objItem.Description
      write-host "Identifying Number: " $objItem.IdentifyingNumber
      write-host "Installation Date: " $objItem.InstallDate
      write-host "Installation Date 2: " $objItem.InstallDate2
      write-host "Installation Location: " $objItem.InstallLocation
      write-host "Installation State: " $objItem.InstallState
      write-host "Name: " $objItem.Name
      write-host "Package Cache: " $objItem.PackageCache
      write-host "SKU Number: " $objItem.SKUNumber
      write-host "Vendor: " $objItem.Vendor
      write-host "Version: " $objItem.Version
      write-host
}

3. 列出制定计算机共享文件夹信息

#===========================================
# 列出共享文件夹信息
#===========================================
$strComputer = "ziz-vmm-lihua" #"."
$colItems = get-wmiobject -class "Win32_Share" -namespace "root\CIMV2" `
-computername $strComputer
foreach ($objItem in $colItems) {
      write-host "Access Mask: " $objItem.AccessMask
      write-host "Allow Maximum: " $objItem.AllowMaximum
      write-host "Caption: " $objItem.Caption
      write-host "Description: " $objItem.Description
      write-host "Installation Date: " $objItem.InstallDate
      write-host "Maximum Allowed: " $objItem.MaximumAllowed
      write-host "Name: " $objItem.Name
      write-host "Path: " $objItem.Path
      write-host "Status: " $objItem.Status
      write-host "Type: " $objItem.Type
      write-host
}

4.列出一台机器里所有文件夹信息

$strComputer = "." #也可以是远程机器如zivsoft-lihua
$colItems = get-wmiobject -class "Win32_Directory" -namespace "root\CIMV2" `
-computername $strComputer
foreach ($objItem in $colItems) {
      write-host "Access Mask: " $objItem.AccessMask
      write-host "Archive: " $objItem.Archive
      write-host "Caption: " $objItem.Caption
      write-host "Compressed: " $objItem.Compressed
      write-host "Compression Method: " $objItem.CompressionMethod
      write-host "Creation Class Name: " $objItem.CreationClassName
      write-host "Creation Date: " $objItem.CreationDate
      write-host "CS Creation Class Name: " $objItem.CSCreationClassName
      write-host "CS Name: " $objItem.CSName
      write-host "Description: " $objItem.Description
      write-host "Drive: " $objItem.Drive
      write-host "8.3 File Name: " $objItem.EightDotThreeFileName
      write-host "Encrypted: " $objItem.Encrypted
      write-host "Encryption Method: " $objItem.EncryptionMethod
      write-host "Extension: " $objItem.Extension
      write-host "File Name: " $objItem.FileName
      write-host "File Size: " $objItem.FileSize
      write-host "File Type: " $objItem.FileType
      write-host "FS Creation Class Name: " $objItem.FSCreationClassName
      write-host "FS Name: " $objItem.FSName
      write-host "Hidden: " $objItem.Hidden
      write-host "InstallationDate: " $objItem.InstallDate
      write-host "In Use Count: " $objItem.InUseCount
      write-host "Last Accessed: " $objItem.LastAccessed
      write-host "Last Modified: " $objItem.LastModified
      write-host "Name: " $objItem.Name
      write-host "Path: " $objItem.Path
      write-host "Readable: " $objItem.Readable
      write-host "Status: " $objItem.Status
      write-host "System: " $objItem.System
      write-host "Writeable: " $objItem.Writeable
      write-host
}

5. 列出指定机器中的所有Scheduled Tasks列表

$strComputer = "zivosft-lihua-pc"
$colItems = get-wmiobject -class "Win32_ScheduledJob" -namespace "root\CIMV2" `
-computername $strComputer
foreach ($objItem in $colItems) {
      write-host "Caption: " $objItem.Caption
      write-host "Command: " $objItem.Command
      write-host "Days Of Month: " $objItem.DaysOfMonth
      write-host "Days Of Week: " $objItem.DaysOfWeek
      write-host "Description: " $objItem.Description
      write-host "Elapsed Time: " $objItem.ElapsedTime
      write-host "Installation Date: " $objItem.InstallDate
      write-host "Interact With Desktop: " $objItem.InteractWithDesktop
      write-host "Job ID: " $objItem.JobId
      write-host "Job Status: " $objItem.JobStatus
      write-host "Name: " $objItem.Name
      write-host "Notify: " $objItem.Notify
      write-host "Owner: " $objItem.Owner
      write-host "Priority: " $objItem.Priority
      write-host "Run Repeatedly: " $objItem.RunRepeatedly
      write-host "Start Time: " $objItem.StartTime
      write-host "Status: " $objItem.Status
      write-host "Time Submitted: " $objItem.TimeSubmitted
      write-host "Until Time: " $objItem.UntilTime
      write-host
}

6. 一个动态输出自定义cmdlets帮助信息与Examples的函数,帮助你学习陌生的cmdlets

#======================================================
# Usage: Updated by Lihua at 05/05/2009 zivsoft.com
# OutputHelp SqlServerCmdletSnapin100 SqlCmdletsFolder
# OutputHelp HelloWorldPSSnapin HelloFolder
# Output UnknownPSSnapIn UnknownCmdletsFolder
#======================================================
function OutputHelp{
$snapin=$Args[0] #the snapin that you will specified
#verify parameter
if($snapin -eq $null){
throw "The first parameter Snapin is null"
    }
$folder=$Args[1] #the folder where files will stored
$snapins = Get-PSSnapin -Name $snapin
if($snapins -eq $null){
#add pssnapin
        Add-PSSnapin $snapin
    }   
$d =  Get-Command -PSSnapin $snapin
#verify the existing snapin has the command-let
if($d -eq $null){
throw "The snapin $snapin has none cmdlets"
    }
"Total:" + $d.Count
$i = 0
#Verify the folder exists
if([System.IO.Directory]::Exists([AppDomain]::CurrentDomain.BaseDirectory.ToString() + $folder) -eq $false){
        md $folder
    }
$d | foreach -process{
$i++
"Printing" + $i
$cmdlet = $_.Name
$path = ".\$folder\"+$cmdlet + ".ps1"
        Get-Help -Examples $cmdlet > $path
    }
"Successfully"
}

7. 关闭(重启)远程计算机

#=================================
#在有管理员权限下关闭远程计算机
#Copyright http://www.zivsoft.com
#=================================
function ShutdownRemoteMachine{
param ([string]$machineName=$null)
$os = Get-WmiObject Win32_OperatingSystem -computerName $machineName
#shutdown /m \\MACHINENAME /r /f
$os.Win32Shutdown(6,0) #远程关机
}

文章连接:http://www.cnblogs.com/architect/archive/2009/05/05/1450050.html
作者相关:http://www.zivsoft.com

相关文章 热门文章
  • 文件共享的12条军规——多一点规划可以使你的共享文件夹环境更合理
  • Exchange2007通过PowerShell批量创建用户邮箱指定组成员邮箱
  • PowerShell命令解释器技巧
  • PowerShell脚本优化技巧
  • Windows PowerShell改变Exchange Server 2007管理工作
  • Windows PowerShell 講座 (9)—模組化
  • 精通Windows Server 2008 多元密码策略之PowerShell篇
  • 通过PowerShell批量创建用户邮箱
  • Windows PowerShell 講座 (8)—迴圈與流程控制
  • Windows PowerShell 講座 (7)—運算子(下)
  • Windows PowerShell講座(6)—運算子(上)
  • Windows PowerShell 講座(5)—儲存資料的其他方式及編寫指令碼的前置準備
  • “http 500内部服务器错误”的解决方法
  • 利用Windows 2000 Server的RRAS实现VPN服务器
  • 用凤凰万能启动盘解决本地/域管理员密码丢失
  • Win2003 Server企业版安装配置
  • Active directory 灾难恢复
  • Windows 2000/03域和活动目录
  • 如何在vmware4上创建windows 2003群集
  • MSI文件制作全过程
  • Win2000命令全集(一)
  • Windows 2000/AD技巧
  • 此系统的本地策略不允许您采用交互式登录解决方法
  • Win2000路由的安装与设置实现不同网段互通
  • 自由广告区
     
    最新软件下载
  • SharePoint Server 2010 部署文档
  • Exchange 2010 RTM升级至SP1 教程
  • Exchange 2010 OWA下RBAC实现的组功能...
  • Lync Server 2010 Standard Edition 标..
  • Lync Server 2010 Enterprise Edition...
  • Forefront Endpoint Protection 2010 ...
  • Lync Server 2010 Edge 服务器部署文档
  • 《Exchange 2003专家指南》
  • Mastering Hyper-V Deployment
  • Windows Server 2008 R2 Hyper-V
  • Microsoft Lync Server 2010 Unleashed
  • Windows Server 2008 R2 Unleashed
  • 今日邮件技术文章
  • 腾讯,在创新中演绎互联网“进化论”
  • 华科人 张小龙 (中国第二代程序员 QQ...
  • 微软推出新功能 提高Hotmail密码安全性
  • 快压技巧分享:秒传邮件超大附件
  • 不容忽视的邮件营销数据分析过程中的算..
  • 国内手机邮箱的现状与未来发展——访尚..
  • 易观数据:2011Q2中国手机邮箱市场收入..
  • 穿越时空的爱恋 QQ邮箱音视频及贺卡邮件
  • Hotmail新功能:“我的朋友可能被黑了”
  • 入侵邻居网络发骚扰邮件 美国男子被重..
  • 网易邮箱莫子睿:《非你莫属》招聘多过..
  • 中国电信推广189邮箱绿色账单
  • 最新专题
  • 鸟哥的Linux私房菜之Mail服务器
  • Exchange Server 2010技术专题
  • Windows 7 技术专题
  • Sendmail 邮件系统配置
  • 组建Exchange 2003邮件系统
  • Windows Server 2008 专题
  • ORF 反垃圾邮件系统
  • Exchange Server 2007 专题
  • ISA Server 2006 教程专题
  • Windows Vista 技术专题
  • “黑莓”(BlackBerry)专题
  • Apache James 专题
  • 分类导航
    邮件新闻资讯:
    IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮
    电子邮箱 | 反垃圾邮件|邮件客户端|网络安全
    行业数据 | 邮件人物 | 网站公告 | 行业法规
    网络技术:
    邮件原理 | 网络协议 | 网络管理 | 传输介质
    线路接入 | 路由接口 | 邮件存储 | 华为3Com
    CISCO技术 | 网络与服务器硬件
    操作系统:
    Windows 9X | Linux&Uinx | Windows NT
    Windows Vista | FreeBSD | 其它操作系统
    邮件服务器:
    程序与开发 | Exchange | Qmail | Postfix
    Sendmail | MDaemon | Domino | Foxmail
    KerioMail | JavaMail | Winwebmail |James
    Merak&VisNetic | CMailServer | WinMail
    金笛邮件系统 | 其它 |
    反垃圾邮件:
    综述| 客户端反垃圾邮件|服务器端反垃圾邮件
    邮件客户端软件:
    Outlook | Foxmail | DreamMail| KooMail
    The bat | 雷鸟 | Eudora |Becky! |Pegasus
    IncrediMail |其它
    电子邮箱: 个人邮箱 | 企业邮箱 |Gmail
    移动电子邮件:服务器 | 客户端 | 技术前沿
    邮件网络安全:
    软件漏洞 | 安全知识 | 病毒公告 |防火墙
    攻防技术 | 病毒查杀| ISA | 数字签名
    邮件营销:
    Email营销 | 网络营销 | 营销技巧 |营销案例
    邮件人才:招聘 | 职场 | 培训 | 指南 | 职场
    解决方案:
    邮件系统|反垃圾邮件 |安全 |移动电邮 |招标
    产品评测:
    邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端
    广告联系 | 合作联系 | 关于我们 | 联系我们 | 繁體中文
    版权所有:邮件技术资讯网©2003-2010 www.5dmail.net, All Rights Reserved
    www.5Dmail.net Web Team   粤ICP备05009143号