I have created this migration script for a Win7 deployment. It takes a parameter "-site" and then does a few things on the way to creating folders.
It doesnt seem to like the paramter input. Also, i tried using [CmdletBinding()] and powershell ISE v3 doesnt like it at all. Does cmdletbinding need to be part of a function? I have tried making this a function and it makes no difference.
I've copied the script below. In theory, you should be able to create a couple of directories on your c drive and run it with the -site "test" parameter. Help, i have been looking at this too long :)
<code>
<#
.SYNOPSIS
Folder creation
.DESCRIPTION
Creates folders in one location, based on the name of the
folders from another location.
.EXAMPLE
n/a
.NOTES
Created for the Win7 migration, to create a UserDocs folder
under a new location, to be populated with data from the
legacy location.
.PARAMETER
-Site
Example::: Create-Win7Folders -Site WIN01
.Extra Notes
This script accepts a "test" site input. This will
look locally for C:\Mydocuments and C:\UserDocs and
perform the task locally.
#>
#If (!(Get-PSSnapin | where {$_.Name -match "quest.activeroles.admanagement"}))
#{
# Add-PSSnapin quest.activeroles.admanagement
#}
#
# Define **New** UserDocs area
###############################
$TestUserDocs = "C:\UserDocs\"
$WIN01UserDocs = "\\WIN01FS1001\UserDocs\"
$WUS06UserDocs = "\\WUS06FS1001\UserDocs\"
$WHK01UserDocs = "\\WHK01FS1001\UserDocs\"
$WUS03UserDocs = "\\WUS03FS1001\UserDocs\"
$WUS04UserDocs = "\\WUS04FS1001\UserDocs\"
$WIN02UserDocs = "\\WIN02FS1001\UserDocs\"
$WIN03UserDocs = "\\WIN03FS1001\UserDocs\"
$WUS01UserDocs = "\\WUS01FS1002\UserDocs\"
$WFR01UserDocs = "\\WFR01FS1001\UserDocs\"
$WSG01UserDocs = "\\WSG01FS1001\UserDocs\"
$WAU01UserDocs = "\\WAU01FS1001\UserDocs\"
$WJP01UserDocs = "\\WJP01FS1001\UserDocs\"
$WCA01UserDocs = "\\WCA01FS1001\UserDocs\"
$WGB01UserDocs = "\\WGB01FS1001\UserDocs\"
#
# Define **Old** MyDocuments area
###############################
$TestOldDocs = "C:\MyDocuments\"
$WIN01OldDocs = "\\WIN01FS1001\MyDocuments\"
$WUS06OldDocs = "\\WUS06FS1001\MyDocuments\"
$WHK01OldDocs = "\\WHK01FS1001\MyDocuments\"
$WUS03OldDocs = "\\WUS03FS1001\MyDocuments\"
$WUS04OldDocs = "\\WUS04FS1001\MyDocuments\"
$WIN02OldDocs = "\\WIN02FS1001\MyDocuments\"
$WIN03OldDocs = "\\WIN03FS1001\MyDocuments\"
$WUS01OldDocs = "\\WWLFS1029\Users\"
$WFR01OldDocs = "\\WFR01FS1001\MyDocuments\"
$WSG01OldDocs = "\\WSG01FS1001\MyDocuments\"
$WAU01OldDocs = "\\WWLFS1009\Users\"
$WJP01OldDocs = "\\WJP01FS1001\MyDocuments\"
$WCA01OldDocs = "\\WCA01FS1001\MyDocuments\"
$WGB01OldDocs = "\\WGB01FS1001\MyDocuments\"
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$Site
)
If ($Site -like "*Test*") {$OldDocs = $TestOldDocs;$UserDocs = $TestUserDocs}
elseif ($Site -like "*WGB01*") {$OldDocs = $WGB01OldDocs;$UserDocs = $WGB01UserDocs}
elseif ($Site -like "*WIN01*") {$OldDocs = $WIN01OldDocs;$UserDocs = $WIN01UserDocs}
elseif ($Site -like "*WUS06*") {$OldDocs = $WUS06OldDocs;$UserDocs = $WUS06UserDocs}
elseif ($Site -like "*WHK01*") {$OldDocs = $WHK01OldDocs;$UserDocs = $WHK01UserDocs}
elseif ($Site -like "*WUS04*") {$OldDocs = $WUS04OldDocs;$UserDocs = $WUS04UserDocs}
elseif ($Site -like "*WIN02*") {$OldDocs = $WIN02OldDocs;$UserDocs = $WIN02UserDocs}
elseif ($Site -like "*WIN03*") {$OldDocs = $WIN03OldDocs;$UserDocs = $WIN03UserDocs}
elseif ($Site -like "*WUS01*") {$OldDocs = $WUS01OldDocs;$UserDocs = $WUS01UserDocs}
elseif ($Site -like "*WFR01*") {$OldDocs = $WFR01OldDocs;$UserDocs = $WFR01UserDocs}
elseif ($Site -like "*WSG01*") {$OldDocs = $WSG01OldDocs;$UserDocs = $WSG01UserDocs}
elseif ($Site -like "*WAU01*") {$OldDocs = $WAU01OldDocs;$UserDocs = $WAU01UserDocs}
elseif ($Site -like "*WJP01*") {$OldDocs = $WJP01OldDocs;$UserDocs = $WJP01UserDocs}
elseif ($Site -like "*WCA01*") {$OldDocs = $WCA01OldDocs;$UserDocs = $WCA01UserDocs}
#
# Retrieve folders from old UserDocs area
#########################################
$Foldernames = Get-ChildItem $OldDocs -Recurse
For($i = 1; $i -le $foldernames.count; $i++)
{ Write-Progress -Activity "Gathering User Folders......" -status "Finding folder $i" `-percentComplete ($i / $foldernames.count*100) }
Foreach ( $folder in $foldernames ) {
$FullPath = $folder.fullname
$TempName = $folder.name
$name = $TempName.split("$")[0]
$CheckPath = "$($UserDocs)$($name)"
write-verbose "Checking if folder has a user account...."
If (!(get-qaduser -ip samaccountname $name))
{
write-verbose "Dead user account...$($Name)"
}
If (!(Get-ChildItem $CheckPath))
{
Write-verbose "Folder does not exist for $($Name). Creating folder structure and setting permissions........"
}
else
{
$TopFolderPath = $UserDocs + $name
$SimpleACL = get-acl $FullPath
$DocumentsFolderPath = $UserDocs + $name +"\Documents"
$FavFolderPath = $UserDocs + $name +"\Favourites"
$DesktopFolderPath = $UserDocs + $name +"\Desktop"
$MigrateFolderPath = $UserDocs + $name +"\Migrate"
write-verbose "Creating Top-level folder...." -foregroundcolor Green
New-Item $TopFolderPath -type directory
write-verbose "Setting ACL on folder...." -foregroundcolor Green
set-acl $TopFolderPath -aclobject $SimpleACL
$acl = get-acl $FullPath
$account = New-Object System.Security.Principal.NTAccount("Worldwide",$name)
$accountsid = $account.Translate([System.Security.Principal.SecurityIdentifier])
$acl.setowner($account)
set-acl $topfolderpath -AclObject $acl
write-verbose "Creating child folders...." -foregroundcolor Green
New-Item $DocumentsFolderPath -type directory
set-acl $DocumentsFolderPath -AclObject $acl
New-Item $FavFolderPath -type directory
set-acl $FavFolderPath -AclObject $acl
New-Item $DesktopFolderPath -type directory
set-acl $DesktopFolderPath -AclObject $acl
New-Item $MigrateFolderPath -type directory
set-acl $MigrateFolderPath -AclObject $acl
}
}
</code>
Help!!!