从哈希表Create自定义对象 自定义对象非常有用,使用哈希表方法可以轻松创建。PSCustomObject类是专门为此目的设计的。 自定义对象是从函数或脚本返回自定义输出的好方法。 这比返回无法重新格式化或通过管道传递给其他命令的格式化输出更有用。 中的Test-Object function命令设置一些变量值,然后使用这些值创建自定义对象。
New-Object-TypeNameSystem.Version-ArgumentList"1.2.3.4"Major Minor Build Revision --- --- --- ---1234 示例2:Create Internet Explorer COM 对象 此示例创建表示 Internet Explorer 应用程序的 COM 对象的两个实例。 第一个实例使用Property参数哈希表调用Navigate2方法并将 对象的Visible属性设置为$True以...
默认情况下,Select-Object使用ScriptBlock字符串作为属性的名称。 使用哈希表,可以将ScriptBlock的输出标记为添加到每个对象的自定义属性。 可以将多个计算属性添加到传递给Select-Object的每个对象。 PowerShell # Create a calculated property called $_.StartTime.DayOfWeekGet-Process|Select-Object-PropertyProcessName,...
Length;$i++){ "`$iparray["+$i+"]="+$iparray[$i]+"`n" Invoke-Command -ComputerName $iparray[$i] -Credential $Cred -ScriptBlock { Get-WindowsFeature -Name NET-*, Web-* | where {$_.Name -notmatch "Ftp|Web-Application-Proxy"} | Install-WindowsFeature; } }...
Sort-Object cmdlet 根据对象属性值按升序或降序对对象进行排序。 如果命令中不包含排序属性,PowerShell 将使用第一个输入对象的默认排序属性。 如果输入对象的类型没有默认排序属性,PowerShell 将尝试比较对象本身。 有关详细信息,请参阅 说明 部分。 可以按单个属性或多个属性对对象进行排序。 多个属性使用哈希表按...
默认情况下,Select-Object使用ScriptBlock字符串作为属性的名称。 使用哈希表,可以将ScriptBlock的输出标记为添加到每个对象的自定义属性。 可以将多个计算属性添加到传递给Select-Object的每个对象。 PowerShell # Create a calculated property called $_.StartTime.DayOfWeekGet-Process|Select-Object-PropertyProcessName,...
Create powershell object using dynamic properties Create scheduled task that executes as a domain user on a workgroup computer Create timer function that does not use start-sleep Create VHD with PowerShell fails - Solved create/rename folder uppercase Creating a condition with a time range Creating...
functionGlobal:Get-DependentSvs{Get-Service|Where-Object{$_.DependentServices} } When a function is in the global scope, you can use the function in scripts, in functions, and at the command line. Functions create a new scope. The items created in a function, such as variables, exist only...
Where-ObjectCollaborate with us on GitHub The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. PowerShell feedback PowerShell is an open source project. Select a link to pr...
This is by far, the cleanest way to create a custom object. The script is a bit shorter, and it is much more readable than the way I had to do things in the Windows PowerShell 2.0 world. $myhost = $env:COMPUTERNAME $date = (get-date).ToString() ...