Write PowerShell Output To Text File

Here is an example of how I use the Write-Output command to log every update my PowerShell script made.


$items = $list.Items

$output = foreach ($item in $items)
{
Write-Host "Updating" $item["FileLeafRef"]
Write-Output "Updating" $item["FileLeafRef"]

$item["Status"] = "Active"
$item.Update()
}
$output | Out-File E:\SharePoint\PSUpdateStatus.txt

The $output variable needs to wrap the collection of items being updated (the foreach statement) if you want to combine all outputs into the same file. Then use the Write-Output function to state what needs to logged.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s