Créer un sous-répertoire/sous-dossier

Je suis de la création d'un script PowerShell pour "compiler" un tas de documents répartis à travers mes notes. Je voudrais créer la structure de répertoire d'abord, puis de copier les fichiers dans le nouveau répertoire. Je sais comment le faire manuellement, mais je ne suis pas sûr de la façon de l'aborder dans PowerShell. Je suis nouveau à la création de scripts en général, si je comprends la programmation dans différents langages.

Dois-je changer le répertoire courant, puis il suffit de faire quelques plus de répertoires? Ou est-il une approche différente?

C'est ce que j'ai à ce jour:

#Variables
$containerFolder = "F:\FSG\Packet.Fusion for IT and AV Professionals"
$rootFolder = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"


#create the directory structure
md -Path $containerFolder -Name $rootFolder

Je voudrais faire plusieurs répertoires à l'intérieur de $rootFolder, et 1 ou 2 d'entre eux ont leurs propres sous-répertoires. Si je faisais ça à la ligne de commande, je voudrais cd dans le nouveau répertoire, puis md un peu plus. C'est que la façon de le faire avec des scripts?

MODIFIER c'est Ce que je me suis retrouvé en commençant par:

# Compiles the Fusion packet for distribution

###############################
###########Variables###########
###############################

#folder structure
$FSG = "F:\FSG"
$containerFolder = "Packet.Fusion for IT and AV Professionals"
$rootFolder      = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"
$subRoot1        = "Fusion Server"
$subRoot2        = "Scheduling Enhancement and Panels"
$subRoot2sub1    = "Scheduling Panels"
$subRoot3        = "SQL Server"

#source folders
$HW      = "0.Hardware"
$3SMDoc  = "0.Hardware\TPMC-3SM.Documentation"
$4SMDoc  = "0.Hardware\TPMC-4SM.Documentation"
$4SMDDoc = "0.Hardware\TPMC-4SM-FD.Documentation"
$730Doc  = "0.Hardware\TSW-730.Documentation"
$730OLH  = "0.Hardware\TSW-730.OLH"
$CENRVS  = "0.Hardware\CEN-RVS.Notes"

$ProjMgmt = "0.Project Management"

$SW            = "0.Software"
$RVLicensing   = "0.Software
# Compiles the Fusion packet for distribution

###############################
###########Variables###########
###############################

#folder structure
$FSG = "F:\FSG"
$containerFolder = "Packet.Fusion for IT and AV Professionals"
$rootFolder      = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"
$subRoot1        = "Fusion Server"
$subRoot2        = "Scheduling Enhancement and Panels"
$subRoot2sub1    = "Scheduling Panels"
$subRoot3        = "SQL Server"

#source folders
$HW      = "0.Hardware"
$3SMDoc  = "0.Hardware\TPMC-3SM.Documentation"
$4SMDoc  = "0.Hardware\TPMC-4SM.Documentation"
$4SMDDoc = "0.Hardware\TPMC-4SM-FD.Documentation"
$730Doc  = "0.Hardware\TSW-730.Documentation"
$730OLH  = "0.Hardware\TSW-730.OLH"
$CENRVS  = "0.Hardware\CEN-RVS.Notes"

$ProjMgmt = "0.Project Management"

$SW            = "0.Software"
$RVLicensing   = "0.Software
# Compiles the Fusion packet for distribution
###############################
###########Variables###########
###############################
#folder structure
$FSG = "F:\FSG"
$containerFolder = "Packet.Fusion for IT and AV Professionals"
$rootFolder      = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"
$subRoot1        = "Fusion Server"
$subRoot2        = "Scheduling Enhancement and Panels"
$subRoot2sub1    = "Scheduling Panels"
$subRoot3        = "SQL Server"
#source folders
$HW      = "0.Hardware"
$3SMDoc  = "0.Hardware\TPMC-3SM.Documentation"
$4SMDoc  = "0.Hardware\TPMC-4SM.Documentation"
$4SMDDoc = "0.Hardware\TPMC-4SM-FD.Documentation"
$730Doc  = "0.Hardware\TSW-730.Documentation"
$730OLH  = "0.Hardware\TSW-730.OLH"
$CENRVS  = "0.Hardware\CEN-RVS.Notes"
$ProjMgmt = "0.Project Management"
$SW            = "0.Software"
$RVLicensing   = "0.Software\0.RoomView.License"
$RVNotes       = "0.Software\0.RoomView.Notes"
$SQLLicensing  = "0.Software\database.SQL.Licensing"
$SQLNotes      = "0.Software\database.SQL.Notes"
$FRVMarketing  = "0.Software\Fusion RV.Marketing"
$FRVNetworking = "0.Software\Fusion RV.Networking"
$FRVNotes      = "0.Software\Fusion RV.Notes"
###############################
#create the directory structure
###############################
md -Path $containerFolder -Name $rootFolder
cd $FSG\$containerFolder\$rootFolder
md "eControl and xPanels"
md "Fusion Server" #$subRoot1
md "Getting Started as a User"
md "Project Management"
md "RoomView Connected Displays"
md "Scheduling Enhancement and Panels" #$subRoot2
md "SQL Server" #$subRoot3
cd $FSG\$containerFolder\$rootFolder\$subRoot1
md "CEN-RVS"
md "Licenseing Information"
md "Networking"
md "Official Documentation"
md "Prerequisites, including powerShell script"
md "Product Info"
md "Requirements"
md "Tech Info"
md "Windows Authentication to Fusion RV"
cd $FSG\$containerFolder\$rootFolder\$subRoot2
md "Outlook Add-in"
md "Scheduling Panels" #$subRoot2sub1
cd $FSG\$containerFolder\$rootFolder\$subRoot2\$subRoot2sub1
md "TPMC-3SM"
md "TPMC-4SM"
md "TPMC-4SM-FD"
md "TSW-730"
cd $FSG\$containerFolder\$rootFolder\$subRoot3
md "Multi-database model only"
md "SQL Licensing"
.RoomView.License"
$RVNotes = "0.Software
# Compiles the Fusion packet for distribution
###############################
###########Variables###########
###############################
#folder structure
$FSG = "F:\FSG"
$containerFolder = "Packet.Fusion for IT and AV Professionals"
$rootFolder      = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"
$subRoot1        = "Fusion Server"
$subRoot2        = "Scheduling Enhancement and Panels"
$subRoot2sub1    = "Scheduling Panels"
$subRoot3        = "SQL Server"
#source folders
$HW      = "0.Hardware"
$3SMDoc  = "0.Hardware\TPMC-3SM.Documentation"
$4SMDoc  = "0.Hardware\TPMC-4SM.Documentation"
$4SMDDoc = "0.Hardware\TPMC-4SM-FD.Documentation"
$730Doc  = "0.Hardware\TSW-730.Documentation"
$730OLH  = "0.Hardware\TSW-730.OLH"
$CENRVS  = "0.Hardware\CEN-RVS.Notes"
$ProjMgmt = "0.Project Management"
$SW            = "0.Software"
$RVLicensing   = "0.Software\0.RoomView.License"
$RVNotes       = "0.Software\0.RoomView.Notes"
$SQLLicensing  = "0.Software\database.SQL.Licensing"
$SQLNotes      = "0.Software\database.SQL.Notes"
$FRVMarketing  = "0.Software\Fusion RV.Marketing"
$FRVNetworking = "0.Software\Fusion RV.Networking"
$FRVNotes      = "0.Software\Fusion RV.Notes"
###############################
#create the directory structure
###############################
md -Path $containerFolder -Name $rootFolder
cd $FSG\$containerFolder\$rootFolder
md "eControl and xPanels"
md "Fusion Server" #$subRoot1
md "Getting Started as a User"
md "Project Management"
md "RoomView Connected Displays"
md "Scheduling Enhancement and Panels" #$subRoot2
md "SQL Server" #$subRoot3
cd $FSG\$containerFolder\$rootFolder\$subRoot1
md "CEN-RVS"
md "Licenseing Information"
md "Networking"
md "Official Documentation"
md "Prerequisites, including powerShell script"
md "Product Info"
md "Requirements"
md "Tech Info"
md "Windows Authentication to Fusion RV"
cd $FSG\$containerFolder\$rootFolder\$subRoot2
md "Outlook Add-in"
md "Scheduling Panels" #$subRoot2sub1
cd $FSG\$containerFolder\$rootFolder\$subRoot2\$subRoot2sub1
md "TPMC-3SM"
md "TPMC-4SM"
md "TPMC-4SM-FD"
md "TSW-730"
cd $FSG\$containerFolder\$rootFolder\$subRoot3
md "Multi-database model only"
md "SQL Licensing"
.RoomView.Notes"
$SQLLicensing = "0.Software\database.SQL.Licensing" $SQLNotes = "0.Software\database.SQL.Notes" $FRVMarketing = "0.Software\Fusion RV.Marketing" $FRVNetworking = "0.Software\Fusion RV.Networking" $FRVNotes = "0.Software\Fusion RV.Notes" ############################### #create the directory structure ############################### md -Path $containerFolder -Name $rootFolder cd $FSG$containerFolder$rootFolder md "eControl and xPanels" md "Fusion Server" #$subRoot1 md "Getting Started as a User" md "Project Management" md "RoomView Connected Displays" md "Scheduling Enhancement and Panels" #$subRoot2 md "SQL Server" #$subRoot3 cd $FSG$containerFolder$rootFolder$subRoot1 md "CEN-RVS" md "Licenseing Information" md "Networking" md "Official Documentation" md "Prerequisites, including powerShell script" md "Product Info" md "Requirements" md "Tech Info" md "Windows Authentication to Fusion RV" cd $FSG$containerFolder$rootFolder$subRoot2 md "Outlook Add-in" md "Scheduling Panels" #$subRoot2sub1 cd $FSG$containerFolder$rootFolder$subRoot2$subRoot2sub1 md "TPMC-3SM" md "TPMC-4SM" md "TPMC-4SM-FD" md "TSW-730" cd $FSG$containerFolder$rootFolder$subRoot3 md "Multi-database model only" md "SQL Licensing"
.RoomView.License"
$RVNotes = "0.Software
# Compiles the Fusion packet for distribution

###############################
###########Variables###########
###############################

#folder structure
$FSG = "F:\FSG"
$containerFolder = "Packet.Fusion for IT and AV Professionals"
$rootFolder      = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"
$subRoot1        = "Fusion Server"
$subRoot2        = "Scheduling Enhancement and Panels"
$subRoot2sub1    = "Scheduling Panels"
$subRoot3        = "SQL Server"

#source folders
$HW      = "0.Hardware"
$3SMDoc  = "0.Hardware\TPMC-3SM.Documentation"
$4SMDoc  = "0.Hardware\TPMC-4SM.Documentation"
$4SMDDoc = "0.Hardware\TPMC-4SM-FD.Documentation"
$730Doc  = "0.Hardware\TSW-730.Documentation"
$730OLH  = "0.Hardware\TSW-730.OLH"
$CENRVS  = "0.Hardware\CEN-RVS.Notes"

$ProjMgmt = "0.Project Management"

$SW            = "0.Software"
$RVLicensing   = "0.Software
# Compiles the Fusion packet for distribution
###############################
###########Variables###########
###############################
#folder structure
$FSG = "F:\FSG"
$containerFolder = "Packet.Fusion for IT and AV Professionals"
$rootFolder      = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"
$subRoot1        = "Fusion Server"
$subRoot2        = "Scheduling Enhancement and Panels"
$subRoot2sub1    = "Scheduling Panels"
$subRoot3        = "SQL Server"
#source folders
$HW      = "0.Hardware"
$3SMDoc  = "0.Hardware\TPMC-3SM.Documentation"
$4SMDoc  = "0.Hardware\TPMC-4SM.Documentation"
$4SMDDoc = "0.Hardware\TPMC-4SM-FD.Documentation"
$730Doc  = "0.Hardware\TSW-730.Documentation"
$730OLH  = "0.Hardware\TSW-730.OLH"
$CENRVS  = "0.Hardware\CEN-RVS.Notes"
$ProjMgmt = "0.Project Management"
$SW            = "0.Software"
$RVLicensing   = "0.Software\0.RoomView.License"
$RVNotes       = "0.Software\0.RoomView.Notes"
$SQLLicensing  = "0.Software\database.SQL.Licensing"
$SQLNotes      = "0.Software\database.SQL.Notes"
$FRVMarketing  = "0.Software\Fusion RV.Marketing"
$FRVNetworking = "0.Software\Fusion RV.Networking"
$FRVNotes      = "0.Software\Fusion RV.Notes"
###############################
#create the directory structure
###############################
md -Path $containerFolder -Name $rootFolder
cd $FSG\$containerFolder\$rootFolder
md "eControl and xPanels"
md "Fusion Server" #$subRoot1
md "Getting Started as a User"
md "Project Management"
md "RoomView Connected Displays"
md "Scheduling Enhancement and Panels" #$subRoot2
md "SQL Server" #$subRoot3
cd $FSG\$containerFolder\$rootFolder\$subRoot1
md "CEN-RVS"
md "Licenseing Information"
md "Networking"
md "Official Documentation"
md "Prerequisites, including powerShell script"
md "Product Info"
md "Requirements"
md "Tech Info"
md "Windows Authentication to Fusion RV"
cd $FSG\$containerFolder\$rootFolder\$subRoot2
md "Outlook Add-in"
md "Scheduling Panels" #$subRoot2sub1
cd $FSG\$containerFolder\$rootFolder\$subRoot2\$subRoot2sub1
md "TPMC-3SM"
md "TPMC-4SM"
md "TPMC-4SM-FD"
md "TSW-730"
cd $FSG\$containerFolder\$rootFolder\$subRoot3
md "Multi-database model only"
md "SQL Licensing"
.RoomView.License"
$RVNotes = "0.Software
# Compiles the Fusion packet for distribution
###############################
###########Variables###########
###############################
#folder structure
$FSG = "F:\FSG"
$containerFolder = "Packet.Fusion for IT and AV Professionals"
$rootFolder      = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"
$subRoot1        = "Fusion Server"
$subRoot2        = "Scheduling Enhancement and Panels"
$subRoot2sub1    = "Scheduling Panels"
$subRoot3        = "SQL Server"
#source folders
$HW      = "0.Hardware"
$3SMDoc  = "0.Hardware\TPMC-3SM.Documentation"
$4SMDoc  = "0.Hardware\TPMC-4SM.Documentation"
$4SMDDoc = "0.Hardware\TPMC-4SM-FD.Documentation"
$730Doc  = "0.Hardware\TSW-730.Documentation"
$730OLH  = "0.Hardware\TSW-730.OLH"
$CENRVS  = "0.Hardware\CEN-RVS.Notes"
$ProjMgmt = "0.Project Management"
$SW            = "0.Software"
$RVLicensing   = "0.Software\0.RoomView.License"
$RVNotes       = "0.Software\0.RoomView.Notes"
$SQLLicensing  = "0.Software\database.SQL.Licensing"
$SQLNotes      = "0.Software\database.SQL.Notes"
$FRVMarketing  = "0.Software\Fusion RV.Marketing"
$FRVNetworking = "0.Software\Fusion RV.Networking"
$FRVNotes      = "0.Software\Fusion RV.Notes"
###############################
#create the directory structure
###############################
md -Path $containerFolder -Name $rootFolder
cd $FSG\$containerFolder\$rootFolder
md "eControl and xPanels"
md "Fusion Server" #$subRoot1
md "Getting Started as a User"
md "Project Management"
md "RoomView Connected Displays"
md "Scheduling Enhancement and Panels" #$subRoot2
md "SQL Server" #$subRoot3
cd $FSG\$containerFolder\$rootFolder\$subRoot1
md "CEN-RVS"
md "Licenseing Information"
md "Networking"
md "Official Documentation"
md "Prerequisites, including powerShell script"
md "Product Info"
md "Requirements"
md "Tech Info"
md "Windows Authentication to Fusion RV"
cd $FSG\$containerFolder\$rootFolder\$subRoot2
md "Outlook Add-in"
md "Scheduling Panels" #$subRoot2sub1
cd $FSG\$containerFolder\$rootFolder\$subRoot2\$subRoot2sub1
md "TPMC-3SM"
md "TPMC-4SM"
md "TPMC-4SM-FD"
md "TSW-730"
cd $FSG\$containerFolder\$rootFolder\$subRoot3
md "Multi-database model only"
md "SQL Licensing"
.RoomView.Notes"
$SQLLicensing = "0.Software\database.SQL.Licensing" $SQLNotes = "0.Software\database.SQL.Notes" $FRVMarketing = "0.Software\Fusion RV.Marketing" $FRVNetworking = "0.Software\Fusion RV.Networking" $FRVNotes = "0.Software\Fusion RV.Notes" ############################### #create the directory structure ############################### md -Path $containerFolder -Name $rootFolder cd $FSG$containerFolder$rootFolder md "eControl and xPanels" md "Fusion Server" #$subRoot1 md "Getting Started as a User" md "Project Management" md "RoomView Connected Displays" md "Scheduling Enhancement and Panels" #$subRoot2 md "SQL Server" #$subRoot3 cd $FSG$containerFolder$rootFolder$subRoot1 md "CEN-RVS" md "Licenseing Information" md "Networking" md "Official Documentation" md "Prerequisites, including powerShell script" md "Product Info" md "Requirements" md "Tech Info" md "Windows Authentication to Fusion RV" cd $FSG$containerFolder$rootFolder$subRoot2 md "Outlook Add-in" md "Scheduling Panels" #$subRoot2sub1 cd $FSG$containerFolder$rootFolder$subRoot2$subRoot2sub1 md "TPMC-3SM" md "TPMC-4SM" md "TPMC-4SM-FD" md "TSW-730" cd $FSG$containerFolder$rootFolder$subRoot3 md "Multi-database model only" md "SQL Licensing"
.RoomView.Notes"
$SQLLicensing = "0.Software\database.SQL.Licensing" $SQLNotes = "0.Software\database.SQL.Notes" $FRVMarketing = "0.Software\Fusion RV.Marketing" $FRVNetworking = "0.Software\Fusion RV.Networking" $FRVNotes = "0.Software\Fusion RV.Notes" ############################### #create the directory structure ############################### md -Path $containerFolder -Name $rootFolder cd $FSG$containerFolder$rootFolder md "eControl and xPanels" md "Fusion Server" #$subRoot1 md "Getting Started as a User" md "Project Management" md "RoomView Connected Displays" md "Scheduling Enhancement and Panels" #$subRoot2 md "SQL Server" #$subRoot3 cd $FSG$containerFolder$rootFolder$subRoot1 md "CEN-RVS" md "Licenseing Information" md "Networking" md "Official Documentation" md "Prerequisites, including powerShell script" md "Product Info" md "Requirements" md "Tech Info" md "Windows Authentication to Fusion RV" cd $FSG$containerFolder$rootFolder$subRoot2 md "Outlook Add-in" md "Scheduling Panels" #$subRoot2sub1 cd $FSG$containerFolder$rootFolder$subRoot2$subRoot2sub1 md "TPMC-3SM" md "TPMC-4SM" md "TPMC-4SM-FD" md "TSW-730" cd $FSG$containerFolder$rootFolder$subRoot3 md "Multi-database model only" md "SQL Licensing"

Est-il des avantages à la création de la leafiest la plupart des sous-répertoires, et par conséquent, faire PowerShell créer le milieu?

Sont il des inconvénients à le faire de cette façon?

L'inconvénient est que ce script est ridiculement long, compliqué et difficile à maintenir. =) Merci de modifier votre réponse.

OriginalL'auteur YetAnotherRandomUser | 2014-01-07