如何在PowerShell中创建特定的用户日志文件? [英] How to create specific user log files in PowerShell?

查看:125
本文介绍了如何在PowerShell中创建特定的用户日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一个问题已得到解答,但是这些是我不需要的日志文件,因此无法正常工作. PowerShell的这一部分是我尚未学习的.我正在尝试执行以下操作:我编写了一个脚本来创建用户,邮箱,文件夹等,但是我想启用一个日志文件,简单明了.

I know there are question that is already answered however those are the log files I don't need and I can't get it to work. This part of PowerShell is something I didn't learned yet. I'm trying to do the following: I wrote a script to create users, mailboxes, folders etc however I want to enable a log file, just simple and plain.

只有某些人可以访问,并且日志文件包含以下信息,例如: PSmith是在2019年1月29日创建的用户帐户JDoe.

Something only certain people can access and where the log files have the following info, for example: PSmith created on 01/29/2019 the user account JDoe.

我该怎么做?我尝试了很多在线发现的内容,但是必须重写整个脚本才能使用.

How can I do this? I tried a lot found online however I have to rewrite my whole script for some to work.

推荐答案

我相信您需要类似的东西,否则请提供更多代码.

I believe you need something like this, if not please provide more code.

$creator = (get-aduser $env:username | Select Name).Name
$date = get-date -UFormat "%d/%m/%Y"

我相信您的脚本中有$user.

$log = $creator + "created on " + $date + " the user account " + $user.Name
Out-File $log "C:\temp\log.csv"

这篇关于如何在PowerShell中创建特定的用户日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆