I was wondering if there is a way I could create multiple folders from a TXT document in windows PowerShell or CMD? I have a TXT file full of drawing numbers, like 5614-E-1459_SH 1 (except there are about 500 hundred of them). Due to policies at my job I am not allowed to use third party software, so I was wondering if there was a way to do this from the command prompt or Windows PowerShell? I know that mkdir "C:\temp\5614-E-1459_SH 1" will create one of the folders I need. But is there a way to extract the files from a TXT and make it output into folders, without third party software like Text2Folders?
I have gotten this far with the PowerShell script, but as I don't have admin writes at work (where its needed most) I get the Set-ExecutionPolicy error. Is there a work around this?
$Users = Get-Content "C:\Users\usermgx\Desktop\folderDir.txt"
ForEach ($user in $users)
{
$newPath = Join-Path "C:\Users\usermgx\Desktop\Dir" -childpath $user
New-Item $newPath -type directory
}
First, you need to update your execution policy so that you can run scripts. You can do it permanently from an administrative PowerShell prompt by running:
Set-ExecutionPolicty RemoteSigned -Scope LocalMachine
If you don't have administrative rights, you can set the execution policy when you call the powershell.exe executable. From CMD:
powershell.exe -ExecutionPolicy RemoteSigned -Command C:\Path\to\your\script.ps1
Finally, you can run your script from the PowerShell ISE. Just open a new untitled document, enter your code, and hit F5, which will execute the code in script pane. I don't believe this is blocked by the execution policy.
Get-Content "C:\Users\usermgx\Desktop\folderDir.txt" |
ForEach-Object {
$dirPath = Join-Path "C:\Users\usermgx\Desktop\Dir" $_
New-Item $dirPath -ItemType Directory
}
Fortunately for what you are trying to do this is pretty easy to do with a CMD script and you won;t have to muck with the execution policy:
@echo off
for /F %%u in (C:\Users\usermgx\Desktop\folderDir.txt) DO (
mkdir "C:\Users\usermgx\Desktop\Dir\"%%u
)
If you want your powershell version to work you must chenge the execution policy as you've noted. But without admin access, you'll have to limit the scope to just yourself, like this:
set-executionpolicy -scope CurrentUser -ExecutionPolicy RemoteSigned
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With