我正在运行一个脚本来获取下面给出的磁盘级别信息。
disk.ps1:
Get-WmiObject Win32_DiskDrive | % {
$disk = $_
$partitions = "ASSOCIATORS OF " +
"{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
"WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Get-WmiObject -Query $partitions | % {
$partition = $_
$drives = "ASSOCIATORS OF " +
"{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
"WHERE AssocClass = Win32_LogicalDiskToPartition"
Get-WmiObject -Query $drives | % {
New-Object -Type PSCustomObject -Property @{
Disk = $disk.SerialNumber
Letter = $_.DeviceID
}
}
}
}
当我在Windows计算机本身上执行上述摘要时,输出为:
字母磁盘--------------- H:XXX_46_0_80987_XXXXXXXX_B2FD_47BB_BC36_AAF4F3029A00 l:xxx_46_0_80987_xxxxx_b2fd_47bb_bc36_aaf4f3029a00 问:XXX_46_0_80987_41A13CD9_B2FD_47BB_BC36_AAF4F3029A00
现在,我正在尝试使用pywinrm
执行相同的脚本。
disk.py:
complete = <string which is equivalent to above script>
winrm_connector = winrm.Session('*.X.X.X', auth=('XXXX','XXXXXX.1'))
response = winrm_connector.run_ps(complete)
print response.std_out
执行此操作,我将输出为:
字母磁盘--------------- H:XXX_46_0_80987_XXXXX_B2FD_47BB_B ... l:xxx_46_0_80987_xxxxx_b2fd_47bb_b ... 问:XXX_46_0_80987_41A13CD9_B2FD_47BB_B ...
请阐明WinRM是在截断输出还是外壳正在截断输出。
我认为外壳没有这样做,因为当我使用PowerShell执行脚本时,我能够获得整个输出。
powershell自动截断了宽列。为了避免,您可以通过在PowerShell代码中通过Format-Table -AutoSize
将数据输送来使用自动尺寸的列。由于您正在通过python调用命令,该命令不知道PowerShell对象,因此您可能还需要通过Out-String
将Format-Table
输出转换为字符串(对线长度的值很大)。
... | Format-Table -AutoSize | Out-String -Width 4096