Create Shares on Remote Servers

12 12 2011

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")
}

Advertisement

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.