我没有完整输出以下代码。
例如:
DriveSpace : {174, 0, 98, 171...}
注意171之后的省略号(...)。之后跳过其余的输出。您可以运行以下脚本来查看我的输出。
#Start of script
$cpu = gwmi -Class Win32_Processor | Select-Object NumberOfCores,NumberOfLogicalProcessors
$memory = gwmi -class win32_physicalmemory | Select-Object {[math]::truncate($_.capacity / 1GB)}
$HostDescription= gwmi -Class Win32_OperatingSystem
$fqdn = "$env:computername.$env:userdnsdomain"
$OS = (gwmi Win32_OperatingSystem)
$OSarchitecture = (gwmi Win32_OperatingSystem)
$disk = gwmi Win32_LogicalDisk | Select-Object DeviceID, volumeName, {[math]::truncate($_.size / 1GB)}
$timezone = [System.TimeZone]::CurrentTimeZone
$fire = netsh advfirewall show publicprofile | select-string state
$firematch = $fire -match "off"
$slmgrResult = cscript c:\windows\system32\slmgr.vbs /dli | Select-string "License Status"
$activation = $slmgrResult -match "Licensed"
$apps = gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |Select DisplayName, DisplayVersion, Publisher, InstallDate
$network = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'True'" | select-object IPAddress, DefaultIPGateway, DNSDomain, IPSubnet
$props = @{
NumberOfCores = $cpu.NumberOfCores
NumberOfLogicalProcessors = $cpu.NumberOfLogicalProcessors
Memory = $memory.{[math]::truncate($_.capacity / 1GB)}
HostDescription = $HostDescription.Description
FQDN = "$env:computername.$env:userdnsdomain"
OS = (gwmi Win32_OperatingSystem).Name
OSarchitecture = $OSarchitecture.OSArchitecture
DriveLetters = $disk.DeviceID
DriveLabels = $disk.volumeName
DriveSpace = $disk.{[math]::truncate($_.size / 1GB)}
timezone = [System.TimeZone]::CurrentTimeZone.StandardName
FirewallDisabled = $firematch
Licensed = $activation
Applications = $apps
IPAddress_Gateway_DNSDomain_subnet = $network.IPAddress, $network.DefaultIPGateway, $network.DNSDomain, $network.IPSubnet
}
New-Object PSObject -Property $props
#End of script
答案 0 :(得分:1)
这不是正式答案,因为我认为OP需要明确他期望的输出。尽管如此,这是一个开始
虽然我还没有找到支持此功能的官方文档,但您只是看到PowerShell如何处理控制台输出。请考虑以下示例,该示例是不同大小的数组的集合。
[pscustomobject]@{
data = "1","2","3","4","5"
}
会产生以下列表样式输出。
data : {1, 2, 3, 4...}
注意5
属性的第五个元素现在有省略号。数据仍在那里。它刚刚在控制台上被截断,使输出更简洁,更易于阅读。在这种情况下,这样做似乎很愚蠢但是有些对象很复杂,PowerShell必须在某处绘制线条。
防止省略号
正如PetSerAL指出的那样,您可以在输出之前使用以下代码行。
$FormatEnumerationLimit=-1
如果查看about_Preference_Variables,您会看到默认设置为4.这将支持您看到的输出。将该值设置为更高或-1,并查看它是否有帮助。
其他潜在问题
在我的评论中,我想提请注意您创建的名为$disk
的变量。输出如下。 注意这是我自己的机器,不会与你的机器匹配。不过,你应该得到图片
DeviceID volumeName [math]::truncate($_.size / 1GB)
-------- ---------- -------------------------------
C: 111
D: Data 499
E: Multimedia 1362
F: 0
G: CentOS 7 x86_64 3
M: Media 2794
Z: 0
如果没有任何其他信息,我只能假设您想要显示一系列可用空间值。鉴于我们可以通过将它们转换为字符串来将这些结果从数组中分解出来。还想更新填充变量的行。
$disk = gwmi Win32_LogicalDisk | Select-Object DeviceID, volumeName, @{Label="Size(GB)";Expression={[math]::truncate($_.size / 1GB)}}
在$ disk`中给我们以下内容
DeviceID volumeName Size(GB)
-------- ---------- --------
C: 111
D: Data 499
E: Multimedia 1362
F: 0
G: CentOS 7 x86_64 3
M: Media 2794
Z: 0
然后,当您构建哈希表时,您可以将数组转换为单个空格分隔的字符串,如下所示:
DriveSpace = [string]($disk."Size(GB)")
相当确定会有更多问题要提出来,但这至少是一个开始。欢迎来到SO。如果可能的话,在这样的情况下向我们展示所需的输出总是一个好主意,所以我们知道你想要实现的目标。即使你认为这很明显。
旁注
您还有其他$disk
可能具有相同问题的属性,例如Applications
这是一个复杂的对象。如果你确实遇到问题并解决这个问题,可能会让你朝着正确的方向前进。
您有多次致电gwmi Win32_OperatingSystem
。您应该将结果保存到您可以在需要时引用的变量中。现在你正在浪费时间调用它并获得相同的结果。例如:
$wmiOS = gwmi Win32_OperatingSystem
答案 1 :(得分:0)
这是由Out-Default
提供的Powershell工作的默认格式。它正在截断DriveSpace数组以显示在控制台的表中,但信息仍然存在。例如,如果键入:
$props.DriveSpace
...你会看到显示完整的数组。默认格式在处理简单数组时的行为不同,而不是处理复杂对象(如您创建的$props
)时的行为。