Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
trying to dive into powershell and make use of all the cool features but running into a snag, trying to figure out a way to output to a text file or HTML, i know there are cmdlets to do this but i cannot figure out how to pipe what i am doing to properly so i can output to the format i want.
$servers=get-content ""
#query each Server in the list
foreach ($s in $servers)
{
$computer= $s
$d= get-wmiobject -computer $computer -query "select deviceid,size from win32_logicaldisk where drivetype=3"
# Cmdlet to display the size of disk partitions
foreach ( $drive in $d )
{
$s= $s + "`n" + $drive.DeviceID + [int]($drive.Size/1073741824) + " GB "
}
$s= $s + "`n"
Write-host $s
}
Write-Host "Script Completed"
any ideas hit on better formatting or a an easier way output the server name and drives would be appreciated!
trying to dive into powershell and make use of all the cool features but running into a snag, trying to figure out a way to output to a text file or HTML, i know there are cmdlets to do this but i cannot figure out how to pipe what i am doing to properly so i can output to the format i want.
$servers=get-content ""
#query each Server in the list
foreach ($s in $servers)
{
$computer= $s
$d= get-wmiobject -computer $computer -query "select deviceid,size from win32_logicaldisk where drivetype=3"
# Cmdlet to display the size of disk partitions
foreach ( $drive in $d )
{
$s= $s + "`n" + $drive.DeviceID + [int]($drive.Size/1073741824) + " GB "
}
$s= $s + "`n"
Write-host $s
}
Write-Host "Script Completed"
any ideas hit on better formatting or a an easier way output the server name and drives would be appreciated!
For example. The general rule in PowerShell: If you're parsing or creating text, you're working too hard. Work with objects instead. There's a whole chapter on this exact technique in "Windows PowerShell: TFM," if you're interested.
This topic is 15 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.