1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#Creating or deleting files for each user Set-Location F:\power\ #User and operation list in a file #Example: #Juan,create #Lucas,delete ForEach($user in Get-Content .\namesandoperation.txt) { if($user.Split(',')[1] -match 'create') { Write-Host 'Create file' $user=$user.Split(',')[0] #Creating file for each user #If the item you are trying to create already exists #Override the default behavior New-Item $user'.txt' -ItemType file -Force } if($user.Split(',')[1] -match 'delete') { Write-Host 'Delete file' $user=$user.Split(',')[0] #Deleting file for each user Remove-Item $user'.txt' } } |