There is a script I am running to get disk level information which given below.
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
}
}
}
}
when I execute the above snippet on the the windows machine itself, the output is:
Letter Disk ------ ---- H: XXX_46_0_80987_XXXXX_b2fd_47bb_bc36_aaf4f3029a00 L: XXX_46_0_80987_XXXXX_b2fd_47bb_bc36_aaf4f3029a00 Q: XXX_46_0_80987_41a13cd9_b2fd_47bb_bc36_aaf4f3029a00
Now I am trying to execute the same script using 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
Executing this I am getting output as:
Letter Disk ------ ---- H: XXX_46_0_80987_XXXXX_b2fd_47bb_b... L: XXX_46_0_80987_XXXXX_b2fd_47bb_b... Q: XXX_46_0_80987_41a13cd9_b2fd_47bb_b...
Please shed some light on whether WinRM is truncating the output or the shell is truncating the output.
I'm thinking the shell is not doing this because when I execute the script using PowerShell I was able to get the entire output.
PowerShell automatically truncates wide columns. To avoid that you can use auto-sized columns by piping the data through
Format-Table -AutoSize
in your PowerShell code. Since you're invoking the command via Python, which doesn't know about PowerShell objects, you may also want to convert theFormat-Table
output to a string by piping it throughOut-String
(with a large value for the line length).