Here is a script that will connect to a list of servers, create a folder structure and then create a share on a folder.
###########################################################################
#
# NAME: Create Share on Remote Servers
#
# AUTHOR: Brady Randolph
#
# COMMENT:
#
# VERSION HISTORY:
# 1.0 12/8/2011 – Initial release
#
###########################################################################
## Gather list of server names
$utlservrs = Get-Content c:\admin\utl_servers.txt
## Loop through each server
foreach ($s in $utlservrs) {
## Create folder structure
if (Test-Path -Path "\\$s\d$\admin") { "Admin folder exists"
New-Item -ItemType directory "\\$s\d$\admin\DAGFileShareWitness"
}
else {"Admin folder doesn’t exist"
New-Item -ItemType directory "\\$s\d$\admin\"
New-Item -ItemType directory "\\$s\d$\admin\DAGFileShareWitness"
}
## Create folder share
"Creating Share"
$cshare = [WMIClass]"\\$s\root\cimv2:Win32_Share"
$result = $cshare.create("D:\admin\DAGFileShareWitness","DAGFileShareWitness",0,25,"DAG File Share Witness")
"Return Result: $result.ReturnValue"
"Adding Exchange Trusted Subsystem group to local admins"
$Domain = ‘mydomain.corp’
$ADGroup = ‘Exchange Trusted Subsystem’
([ADSI]"WinNT://$s/Administrators,group").add("WinNT://$Domain/$ADGroup,group")
}
