Get-Service -name P*

[int]$a = 2
write-output $a [string]$b = "string"
write-output $b #$computername = Read-host "Enter computer name"
#write-output $computername [datetime]$d="12/25/2014"
write-output $d.DayofWeek $service = get-service -name bits
$service.name
$service.status
"Service name is $($service.displayname)" #collection
$services = get-service
$services.count
#loop
$services[1..5]
$services[5..1] $status =2
switch($status)
{
0 {$status_text = 'OK'}
1 {$status_text = 'good'}
2 {$status_text = 'complete'}
default {$status_text = 'unknown'}
} write-output $status_text $service = get-service -name bits
if($service.status -eq "running")
{
"bits is running"
}
else{
"bits is not running"
} #loop
$i=1
do{
write-output "powershell is awsome"
$i = $i+1
} while ($i -le 0) $i = 5
while ($i -gt 0)
{
write-output "power shell new"
$i--
} $services = Get-Service -name b*
ForEach ($service in $services)
{
$service.name
$service.displayname
} 1..3|ForEach-Object -process {
calc
}

test2.ps1

Function Verb-Noun{
param(
[parameter(valuefrompipeline = $true)]
[int]$x
) Begin {$total =0}
Process {$total +=$x}
End { write-Verbose "total = $total"}
} Function Get-ComputerInfo{
param(
[parameter(
Mandatory=$true,
Valuefrompipeline=$true
)]
[Alias("Host")]
[ValidateSet('ws-ace','lexbuild1')]
[string[]]$ComputerName,
[Switch]$ErrorLog,
[string]$LogFile = 'd:\workdirectory\scripts\errorlog.txt'
) Begin{
if($ErrorLog)
{
"Error Log is turned on"
}
else{
"Error log is turned off"
}
} Process{
Foreach($c in $ComputerName)
{
$os = Get-Wmiobject -ComputerName $c -Class Win32_OperatingSystem
$Disk = Get-Wmiobject -ComputerName $c -Class Win32_LogicalDisk -filter "DeviceID ='c:'" $prop =@{
'ComputerName'=$c;
'OS Name'= $os.caption;
'OS build' = $os.buildnumber;
'Free Space' = $Disk.freespace /1gb -as [int]
} $obj = New-object -typename PSObject -Property $prop
write-output $obj
}
}
End{}
}

run get-computerInfo

PowerShell 语法结构的更多相关文章

  1. PowerShell 语法

    PowerShell 之 教程 PowerShell 中变量.函数命名等不区分大小写,但字符串区分大小写 powershell 脚本文件 扩展名为 .ps1 调用操作符 & + Cmd Cmd ...

  2. 04 Linux 指令语法结构与帮助命令

    一.Linux指令语法结构 [tyang3@localhost Desktop]$ command [-options] [arguments] 指令           选项           参 ...

  3. CSS_简介/语法结构/长度单位/应用方式/标签的样式重置/表单样式重置

    一.CSS简介:  w3c(World Wide Web Consortium):万维网联盟,是规定网页标准的一个组织(叫做Web标准) Web标准:是由w3c和其他标准化组织制定的一系列标准的集合, ...

  4. PHP读书笔记(1)-PHP语法结构与变量

    一 .php基础语法 1.php语法结构 标准风格:<?php code; ?>.PHP每句代码用;(分号)结尾.<---就用这个,其他的看看就可以了 短风格:<? code; ...

  5. C#中区别多态、重载、重写的概念和语法结构

    C#中区别多态.重载.重写的概念和语法结构 重写是指重写基类的方法,在基类中的方法必须有修饰符virtual,而在子类的方法中必须指明override. 格式: 基类中: public virtual ...

  6. Java初认识--Java中的语法结构

    Java中的语法结构(程序流程控制) Java的语法结构有四种: 1.顺序结构. 顺序结构很简单,就是按顺序执行,输出就可以了. 2.判断结构. 判断结构的一个代表性的语句是if:if语句有三种格式体 ...

  7. Tcl与Design Compiler (二)——DC综合与Tcl语法结构概述

    1.逻辑综合的概述 synthesis = translation + logic optimization + gate mapping . DC工作流程主要分为这三步 Translation : ...

  8. html dl dt dd标签元素语法结构与使用

    dl dt dd认识及dl dt dd使用方法 标签用于定义列表类型标签. dl dt dd目录 dl dt dd介绍 结构语法 dl dt dd案例 dl dt dd总结 一.dl dt dd认识 ...

  9. PHP基本的语法结构

    学过C语言的话,上手PHP语言就非常快了,如果你有bash shell的基础,那恭喜你,上手PHP会更快,我们先来了解一下一些比较简单的东西,界定符和注释在PHP中的写法: 一 php文档的语法结构 ...

随机推荐

  1. offsetLeft,Left,clientLeft的区别

    offsetLeft,Left,clientLeft的区别 假设 obj 为某个 HTML 控件. obj.offsetTop 指 obj 相对于版面或由 offsetParent 属性指定的父坐标的 ...

  2. 固定定位fixed(IE6)

     position: fixed;          left:200px;          top:100px;          _left:200px;          _top:100px ...

  3. FileUpload上传与下载

    后台代码: public string connstr = "server=128.1.3.113;database=test;uid=sa;pwd=pass"; protecte ...

  4. [转]Perfmon - Windows 自带系统监测工具

    以下内容转自:http://blog.csdn.net/oscar999/article/details/7918385 ---------------------------分割线--------- ...

  5. Google Chrome 源码下载地址 (Google Chrome Source Code Download)

    1. Google Chrome 源码 SVN 地址:http://src.chromium.org/svn.包含有 Chrome.Gears.Webkit.GCC 等源码以及编译依赖工具.Chrom ...

  6. ASP.NET Web API路由规

    默认的规则 在ASP.NET MVC4中 global.asax.cs代码中并无注册默认路由规则的代码 代码如下: public class WebApiApplication : System.We ...

  7. svn resolve/merge

    svn merge http://svn.a.com/branches/20150129_168954_sales-impr_1 svn resolve --accept working web/sr ...

  8. Matrix-Tree定理

    感觉又学到了一个利器! 感谢Vfleaking神犇,传送门 http://vfleaking.blog.163.com/blog/static/1748076342013112523651955/   ...

  9. Rhel6-mailsystem配置文档

    (postfix+dovecot+mysql+extmail) 理论基础:

  10. [vijos P1034] 家族

    寒假给自己定的第一个目标就是把并查集,Tarjan之类搞会.翻了翻笔记,发现并查集是2012年的6月30日学的…早就忘光了…今天敲题目的时候也吃了不少的亏呢… 家族这一题就是并查集的标准题,第一次提交 ...