Georges Orwell
asked on
Help to debug powershell script
Hi all,
Can you help me to debug and improve my script please ?
I have this error when I run the script below:
Here is my csv file:
FullName;Login;Info;Path;f tpAcl;Key
Georges Orwell;gorwell;Compte de test FTP;"D:\NAS_ftp\test\";"re ad,write"; AzertyQWER TY92
Can you help me to debug and improve my script please ?
I have this error when I run the script below:
Import-Module ActiveDirectory
Import-Module WebAdministration
$PWDexp = $true
$PWDmod = $false
$OU="OU=FTP_account,OU=PJA,DC=asso,DC=local"
$file="C:\scripts\NewFtpUsers.csv"
Import-Csv $file -Delimiter ";" | %{
New-ADUser -Name $_.FullName `
-Path $OU `
-SamAccountName $_.login `
-AccountPassword (ConvertTo-SecureString $_.Key -AsPlainText -force)`
-PasswordNeverExpires:$PWDexp `
-CannotChangePassword:$PWDmod `
-Description $_.info `
-Enabled:$True
Write-host ************
write-host $_.Login
write-host $_.path+$_.Login
Write-host ************
if(!(Test-Path $_.path+$_.Login))
{
New-Item $_.path"\"$_.Login -itemType directory
$acl = (Get-Item $_.path).GetAccessControl("Access")
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("ASSO\$_.Login","Modify","ContainerInherit, ObjectInherit","None","Allow")
$acl.AddAccessRule($rule)
Set-Acl $_.path $acl
New-Item IIS:\FTP\ASSO\$_.Login `
-type VirtualDirectory -physicalPath $_.path
Set-ItemProperty IIS:\FTP\ASSO\$_.Login -Name ftpServer.userisolation.mode -Value 3
Set-ItemProperty IIS:\FTP\ASSO\$_.Login -Name ftpServer.directoryBrowse.showFlags -Value 32
Set-ItemProperty IIS:\FTP\ASSO\$_.Login -Name ftpServer.directoryBrowse.showFlags -Value 4
Add-WebConfiguration -Filter /System.FtpServer/Security/Authorization -Value (@{AccessType="Allow"; Users="ASSO\$_.Login"; Permissions=$_.ftpAcl}) -PSPath IIS: -Location "FTP/ASSO/$_.Login"
}
}
Here is my csv file:
FullName;Login;Info;Path;f
Georges Orwell;gorwell;Compte de test FTP;"D:\NAS_ftp\test\";"re
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to you two
Its works fine.
Now I need more help to finish my script because I have another errors:
Here is latest version of my script
Its works fine.
Now I need more help to finish my script because I have another errors:
Here is latest version of my script
Import-Module ActiveDirectory
Import-Module WebAdministration
$PWDexp = $true
$PWDmod = $false
$OU="OU=FTP_account,OU=PJA,DC=ASSO,DC=local"
$file="C:\scripts\NewFtpUsers.csv"
$appCmd="C:\Windows\System32\inetsrv\appcmd.exe "
Import-Csv $file -Delimiter ";" | %{
New-ADUser -Name $_.FullName `
-Path $OU `
-SamAccountName $_.login `
-AccountPassword (ConvertTo-SecureString $_.Key -AsPlainText -force)`
-PasswordNeverExpires:$PWDexp `
-CannotChangePassword:$PWDmod `
-Description $_.info `
-Enabled:$True
Write-host ************
write-host $_.Login
write-host "$($_.Path)\$($_.Login)"
Write-host ************
if (-not (Test-Path "$($_.Path)\$($_.Login)"))
{
New-Item "$($_.Path)\$($_.Login)" -itemType directory
$acl = (Get-Item $_.path).GetAccessControl("Access")
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("ASSO\$($_.Login)","Modify","ContainerInherit, ObjectInherit","None","Allow")
$acl.AddAccessRule($rule)
Set-Acl $_.path $acl
$argsCmd =""add vdir /app.name:"FTP/" /path:/ASSO/"$($_.Login)" /physicalPath:"$($_.Path)\$($_.Login)"""
Invoke-Command "$($appCmd )$($argsCmd)"
Set-ItemProperty IIS:\FTP\ASSO\$_.Login -Name ftpServer.userisolation.mode -Value 3
Set-ItemProperty IIS:\FTP\ASSO\$_.Login -Name ftpServer.directoryBrowse.showFlags -Value 32
Set-ItemProperty IIS:\FTP\ASSO\$_.Login -Name ftpServer.directoryBrowse.showFlags -Value 4
Add-WebConfiguration -Filter /System.FtpServer/Security/Authorization -Value (@{AccessType="Allow"; Users="ASSO\$($_.Login)"; Permissions=$_.ftpAcl}) -PSPath IIS: -Location "FTP/ASSO/$($_.Login)"
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello
I have an new issue like this. Can you help me please?
Here is last version of my code
I have an new issue like this. Can you help me please?
Here is last version of my code
$PWDexp = $true
$PWDmod = $false
$OU="OU=FTP_account,OU=PJA,DC=ASSO,DC=local"
$file="C:\scripts\NewFtpUsers.csv"
try
{
Import-Module ActiveDirectory
Import-Module WebAdministration # Module d'administrattion IIS
Import-Module NTFSSecurity # Module de gestion des ACL FileSystem
# Creation du compte FTP , du VirtualDirectory et du dossier physique
Import-Csv $file -Delimiter ";" | % {
$BuildPath = "$($_.Path)\$($_.Login)" # Construction du chemin physique
if ((-not (Get-ADUser -Filter { SamAccountName -eq $($_.Login) }) -and (-not (Test-Path $($BuildPath)))))
{
# création des comptes AD pour user ftp
New-ADUser -Name $_.FullName `
-Path $OU `
-SamAccountName $_.Login `
-AccountPassword (ConvertTo-SecureString $_.Key -AsPlainText -force)`
-PasswordNeverExpires:$PWDexp `
-CannotChangePassword:$PWDmod `
-Description $_.info `
-Enabled:$True
New-Item $BuildPath -itemType directory # Dossier physique
New-Item IIS:\Sites\FTP\ASSO\"$($_.Login)" -Type VirtualDirectory -PhysicalPath "$($_.Path)\$($_.Login)" # Dossier FTP
Get-Item $BuildPath | Set-NTFSOwner -Account BUILTIN\Administrators
Get-Item $BuildPath | Add-NTFSACCESS -Account ASSO\"$($_.login)" -AccessRights Modify
Add-WebConfiguration -Filter /System.FtpServer/Security/Authorization -Value (@{AccessType="Allow"; `
Users="ASSO\$($_.login)"; Permissions="($_.ftpAcl)"}) -PSPath IIS: -Location "FTP/ASSO/$($_.Login)"
}
}
}
catch {
Write-output $_.InvocationInfo.ScriptLineNumber
Write-output $_.Exception.Message
Write-output $_.Exception.ItemName
}
if(!(Test-Path $_.path+$_.Login))
should read:
Open in new window
or either build a new variable:Open in new window