-Powershell-如何在删除文件后增加数字

时间:2018-03-16 03:18:15

标签: file powershell security scripting increment

创建一个脚本,将当前组和用户与授权组和用户的原始基线进行比较。我坚持创建文件。我想要的例子:

Original.txt

**如果此文件以某种方式被删除,我希望使用当前组和用户重新创建该文件

Original2.txt

**如果再次删除,则执行与上述相同的过程

Original3.txt等依此类推。

不确定它是否重要,但这是我迄今为止完成的但由于文件部分无法完成。

function not-exist { -not (Test-Path $args) }
Set-Alias !exist not-exist -Option "Constant, AllScope"
Set-Alias exist Test-Path -Option "Constant, AllScope"

#To establish baseline
#Get-WmiObject -Class Win32_UserAccount > Original.txt
#Get-LocalUser >> .\Original.txt
#Get-LocalGroup >> .\Original.txt

if(exist .\Original.txt) 
{ 
    cd C:\Users\User\Documents
    Get-WmiObject -Class Win32_UserAccount > Compare.txt
    Get-LocalUser >> .\Compare.txt
    Get-LocalGroup >> .\Compare.txt
}

ElseIf (!exist .\Original.txt)
{
    echo "the file has been deleted"
    echo "recreating baseline as 'Original[x]'"

    #I'm stuck on how to recursively create the file here

    Get-WmiObject -Class Win32_UserAccount > Original[x].txt
    Get-LocalUser >> .\Original[x].txt
    Get-LocalGroup >> .\Original[x].txt
}

Else
{
    #????
    echo "the file neither exists or doesn't exist"
}

我不知道这有多简单或复杂,但我希望我们可以为此努力:)

PS - 如果有任何其他建议,欢迎加入<3

0 个答案:

没有答案