0

I need to create a folder called "logs" on the C: drive of all the machines in my organisation. How can i do this using PowerShell?

I have a script to create the "logs" folder however i need a way to do this on more than 100 machines in Active Directory.

Any advice?

This is the script i'm using to create the folder on my machine:

New-Item -Path c:\Logs -ItemType directory -Force

Is there a way i can apply this script to my entire organisation?

Thanks.

This is not a duplicate as i am trying to do this in a domain environment to all the machines in my organisation and not just one remote server.

  • 3
    Possible duplicate of [PowerShell Create Folder on Remote Server](https://stackoverflow.com/questions/5226772/powershell-create-folder-on-remote-server) – Vladimir Bundalo Mar 20 '18 at 14:48
  • There is a "create new folder" GPO if your in a domain environment. – Alex K. Mar 20 '18 at 14:49
  • @VladimirBundalo That is for a remote server, my issue is different as i need to create a folder in the C: of every PC in my domain. – UnleashedWAR Mar 20 '18 at 16:57
  • @AlexK. But what happens if the folder already exists as in my domain environment, some users already have the folder i want to create and has files in them. I do not want them to disappear. Ideally i want to do this through PowerShell. – UnleashedWAR Mar 20 '18 at 17:10

1 Answers1

0

Since you said it was a domain environment, you don't need to use remote execution, you can access the computer's hard disks remotely.

Get-ADComputer -Filter * | %{ $logsPath = "\\$($_.Name)\c$\Logs"; if ((Test-Path $logsPath) -eq $false) { New-Item -Path $logsPath -ItemType Directory } }

You will want to filter the output of Get-ADComputer or it will apply to every computer in your domain including the servers.

Ashigore
  • 4,618
  • 1
  • 19
  • 39