none
Create Multiple folder on all servers and few more things RRS feed

  • Question

  • Hi All Scripting Master,

    I hope so this is good forum. I have a few question because I still learning PS.  I want write two script with arguments:
    1) Create one folder (without permission to delete main folder, file and subfolders for users - only administrators can delete it) in all domain Servers
    Second Script:
    1) Delete .xls files from created "new_folders" in all servers and export log to csv 
    2) Send mail to user with attachment ( .csv) 
    But I have a few problems:
    1) How to set up ACL for folder without permission to delete
    2) I have problem with Invoke-Command  if I want use it I must enable WinRM on all Servers but I cann't - Can I replace this command with another one? - If yes - on which?
    3) I don't know why Export-CSV don't add logs which files are deleted
    4) Can I write all in one script? 
    Script 1)

    Import-Module ActiveDirectory
    $path = "D:\exist_folder\new_folder"
    $servers = Get-ADComputer -Filter {SamAccountName -like "SRV*"}
    Foreach ($srv in $servers){
    If(!(test-path $path))
     Invoke-Command -ComputerName $srv.Name -ScriptBlock { New-Item -ItemType Directory -Force -Path $path }
    }
     
     Script 2
     $path = "D:\exist_folder\new_folder"
    get-childitem $path -include *.xls -recurse | foreach ($_) {remove-item $_.fullname} | Export-Csv -Path c:\abc\del.csv
    Send-MailMessage -To "User1 <user1@user.com>" -From "User2 <user2@user.com" -Subject "Delete .xls" -SmtpServer "mail.user.com" -Attachments "C:\abc\del.csv"

    • Moved by jrv Wednesday, November 22, 2017 8:21 AM abandoned
    Tuesday, November 21, 2017 1:47 PM

All replies