简体   繁体   中英

How to create a folder on C: drive of several PCs in a network using powershell

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM