Asked by:
Need output in log

Question
-
I have created a script and need to append output in log.
Can somebody help me.
$pc = Get-Content C:\temp\remove.txt | Get-ADComputer -ErrorAction SilentlyContinue $group = GET-ADGROUP -FILTER {Name -like '*.WsusCorporateComputers'} -Properties * | SELECT -ExpandProperty Name $CMgroup = GET-ADGROUP -FILTER {Name -eq 'SCCMgroup'} -Properties * | SELECT -ExpandProperty Name $IvantiGroup = GET-ADGROUP -FILTER {Name -eq 'IvantiGroup'} -Properties * | SELECT -ExpandProperty Name foreach ($item in $group) { Add-Adgroupmember -id $CMgroup -Members $pc.samaccountname Add-Adgroupmember -id $IvantiGroup -Members $pc.samaccountname Remove-ADGroupMember -Identity $item -Members $pc -Confirm:$false }
Lalit
Tuesday, November 3, 2020 4:20 PM
All replies
-
help Out-File -online
\_(ツ)_/
Tuesday, November 3, 2020 4:41 PM -
To output results to a log file you can use the Out-File cmdlet with -append
Your-Command | Out-File C:\Path\to\File.log -Append
But you probably want to run your commands in a Try/Catch block so you can better handle and log errors.
Tuesday, November 3, 2020 4:43 PM -
I have tried this but its created the blank log file.
Lalit
Tuesday, November 3, 2020 4:55 PM -
I have tried this but its created the blank log file.
Nothing in the script that you posted references a log. We can't help you if you don't show us your code or describe what data you are trying to capture in this log.
Tuesday, November 3, 2020 7:30 PM -
Please read the help I posted as it will tell you how to do this.
Another method is to create a transcript. Read the following help to learn how to do that.
help Start-Transcript -online
\_(ツ)_/
Tuesday, November 3, 2020 7:35 PM