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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· Sdcb Chats 技术博客:数据库 ID 选型的曲折之路 - 从 Guid 到自增 ID,再到
· 语音处理 开源项目 EchoSharp
· 《HelloGitHub》第 106 期
· Huawei LiteOS基于Cortex-M4 GD32F4平台移植
· mysql8.0无备份通过idb文件恢复数据过程、idb文件修复和tablespace id不一致处