Multiple folders etc

Welcome Forums General PowerShell Q&A Multiple folders etc

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 3 months ago.

  • Author
  • #84700

    Points: 0
    Rank: Member

    Hi All Scripting Master,

    I hope so this is good forum. 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) in all domain Servers
    Second Script:
    1) Delete .xls files from all 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 WIN-RM 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
    Import-Module ActiveDirectory
    #define variables
    $path = "D:\exist_folder\new_folder"
    $servers = Get-ADComputer -Filter {SamAccountName -like "SRV*"}
    # create folder or no if exist 
    Foreach ($srv in $servers){
    If(!(test-path $path))
     Invoke-Command -ComputerName $srv.Name -ScriptBlock { New-Item -ItemType Directory -Force -Path $path }

    Script 2

     # Remove all .xls files
     $path = "D:\exist_folder\new_folder"
    get-childitem $path -include *.xls -recurse | foreach ($_) {remove-item $_.fullname} | Export-Csv -Path c:\path\del.csv
    #Send mail with attachment to user which files were deleted
    Send-MailMessage -To "User1 " -From "User2 

  • #85090

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Invoke-Command is PowerShell's only method of sending commands to remote computers. If you can't use it, there is no alternative within PowerShell.

  • #85138

    Points: 0
    Rank: Member

    Hi Dan,
    Thanks for response! OK I understand. I copied script via PS to all servers and run it manually

The topic ‘Multiple folders etc’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort