2017-02-23 8 views
0

전 Powershell 전문가가 아니지만 누구든지 폴더에있는 파일을 계산하고 automaticlly 사용자에게 메일을 보내는 스크립트가 있습니까? 우리의 사용자는 로밍 프로필을 가지고집에있는 파일을 계산하고 메일을 보내십시오 - Powershell

(\\ 프로필-SRV \ % 사용자 이름 %)

폴더 이름은 사용자 이름과 동일합니다. 모든 홈 폴더의 파일 수를 계산하고 사용자에게 전자 메일을 보낼 수있는 스크립트를 가질 수 있습니까?

도메인은 다음과 같습니다 FirmaBis.org 총 사용자 : 150

그래서 예에서 계산합니다. AABA 메일을 보낼 수는 카운트 다음 AACA을 [email protected]하고 그래서 스크립트 파일을 계산 및 폴더 이름과 + firmabis.org에 따라 사용자에게 메일을 보내드립니다

[email protected]에게 메일을 보낼 수 있습니다.

감사합니다.

+0

당신은 당신의 자신의 작품의 코드 예제를 제공 할 수 있습니까? 그래서 스크립트 작성 서비스가 아닙니다. 자체 노력이 필요합니다. 우리 중 누구도 다른 사람의 (유급) 일을하기 위해 여기에 있습니다. – bluuf

+0

아무에게도 보내지 않으려 고하지 않습니다. 누군가에게 뭔가가 있다면 그것은 단지 간단한 질문입니다. –

답변

1

나는 지금까지 시도한 것을 보지 못했습니다. 그냥 당신이 출발 제공합니다 :

당신은 GET-ChildItem을.Count 방법의 조합을 사용하여 파일 수의 목록을 얻을 수 있습니다.

(Get-ChildItem D:\FolderName | measure-object).Count 

출력을 변수에 저장할 수 있습니다.

그런 다음, 당신은 당신이 이메일을 보낼 수있는 보내기-은 MailMessageBODY 등의 변수를 전달할 수 있습니다.

+0

나는 아무것도 시작할 수 없었습니다. 감사합니다 :) –

+0

@DavidJackowiak : 대답의 수용은 상당한 것입니다. 먼저 시도한 다음, 우리는 당신을 안내 할 것입니다. :) –

+0

'Measure-Object'는 계산을 위해 중복됩니다. '(Get-ChildItem) .Count' –

2
# Get just the directories in the user directory share, ignore any files, loop over them 
Get-ChildItem -Path '\\server\share' -Directory | ForEach-Object { 

    # List all the files in the current folder (loop variable $_ is the folder) 
    $FilesInFolder = @($_ | Get-ChildItem -Recurse -Force -File) 

    # Count the files 
    $NumFiles = $FilesInFolder.Count 

    # Calculate how many MB they take up, and show it to 2 decimal places 
    $FileSize = $FilesInFolder.Length | Measure-Object -Sum | Select-ExpandProperty Sum 
    $FileSize = "{0:.0}MB" -f ($FileSize/1MB) 

    # Build the email message 
    $Message = @" 
    Hi, 
    The folder for account ($($_.Name)) has $($FilesInFolder.Count) files in it. 
    They add up to $FileSize 
    "@ 

    # Send the message through an SMTP server which is configured to allow 
    # unauthenticated relay emails from the computer running the script. 
    Send-MailMessage -SmtpServer yourmailserver -To "$($_.Name)@FirmaBis.org" -From '[email protected]' -Body $Message 
} 

테스트되지 않은,하지만 ...