+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, Logging Powershell command in Coding and Web Development; Hi, I have put together my own powershell script that will disable computers.I would like to create a log file ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,251
    Thank Post
    898
    Thanked 1,785 Times in 1,537 Posts
    Blog Entries
    12
    Rep Power
    463

    Logging Powershell command

    Hi,

    I have put together my own powershell script that will disable computers.I would like to create a log file of what computers are actually disabled.

    <command> | Out-File -append C:\log.txt

    The above puts a list of computers disabled into a text file. I would like it so it puts a date the command was actioned next to the computer name.

    Also it puts headings above the computer names like the below. Does anyone know if its possible so it doesn't keep putting duplicating the heading please?

    Capture.PNG

    Thanks

  2. #2
    ascott2's Avatar
    Join Date
    Nov 2007
    Posts
    184
    Thank Post
    18
    Thanked 38 Times in 30 Posts
    Rep Power
    21
    Use the -HideTableHeaders switch on the format-table command to hide those headers. To add the current time to the table you will need to customize your table layout. For example <yourcommand> | Format-Table Name, Type, DN, @{Expression={Get-Date};Label="Time"} | out-file log.txt

    Have not tested but should get you going.

  3. Thanks to ascott2 from:

    FN-GM (12th March 2012)

  4. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,251
    Thank Post
    898
    Thanked 1,785 Times in 1,537 Posts
    Blog Entries
    12
    Rep Power
    463
    Thanks pal! Will be trying it tomorrow.

  5. #4

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,251
    Thank Post
    898
    Thanked 1,785 Times in 1,537 Posts
    Blog Entries
    12
    Rep Power
    463
    Thanks for the tips @ascott2 - Just 2 questions. How do i stop it from clipping the DN. I think i need to adjust the width of the column.

    Also how would i prevent it from putting in those 3 blank lines under the log in the txt file please?

    Thanks
    Last edited by FN-GM; 21st March 2012 at 11:12 AM.



SHARE:
+ Post New Thread

Similar Threads

  1. MSFT Create a PowerShell Command Builder
    By EduTech in forum Windows
    Replies: 0
    Last Post: 6th October 2011, 10:39 PM
  2. Help with powershell command
    By Edu-IT in forum Windows
    Replies: 3
    Last Post: 21st September 2011, 01:11 PM
  3. Exchange 2010 - Useful Powershell Commands
    By bodminman in forum Windows Server 2008
    Replies: 0
    Last Post: 10th November 2010, 10:34 AM
  4. Powershell command for account deletion
    By skawarrior in forum Windows Server 2008 R2
    Replies: 0
    Last Post: 4th October 2010, 04:48 PM
  5. Exchange Powershell command help
    By bodminman in forum Windows Server 2008 R2
    Replies: 2
    Last Post: 28th September 2010, 07:42 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •