Link to home
Create AccountLog in
VB Script

VB Script

--

Questions

--

Followers

Top Experts

Avatar of glenn masters
glenn masters

CAN I CONVERT POWERSHELL TO VB SCRIPT
I have the following powershell script and aint got a clue on powershell.   Is there anyway that you can convert or amend a powershell script into a .bat or .vbs file?

BAT file better as I need to add to the script at the end.

Powershell script below.

 
$baseFolder = "C:\DOWNLOADS"

# Replace with the desired value for the subfolders to create
$maxSubFolderSize = 100MB

# Get all files contained in your base folder (could use the -recurse switch if needed)
$allFiles = Get-ChildItem $baseFolder

# Setting the subfolders naming convention : a name and a suffix
$baseSubFolder = "SubFolder-"
[int]$index = 0

# Creating the first subfolder
$subFolder = "SubFolder-" + "$index"
New-Item -Path $subFolder -Type Directory -Force

# Now processing the files
foreach ($file in $allFiles)
{
    # Evaluating the size of the current subfolder
    $subFolderSize = ((Get-ChildItem $subFolder -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1MB)

    # If the current subfolder size is greater than the limit, create a new subfolder and begin to copy files in it
    if([int]$subFolderSize -gt [int]$maxSubFolderSize/1MB)
    {
        $index++
        $subFolder = $baseSubFolder + $index
        New-Item -Path $subFolder -Type Directory -Force
        Write-Verbose -Message "Created folder $subFolder"
        Move-Item $file.FullName -Destination $subFolder
    }
    # If the current subfolder is not yet greater that the limit, continue copying files in it
    else {
        Move-Item $file.FullName -Destination $subFolder
    }
}

Open in new window

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of aikimarkaikimark🇺🇸

Since you understand VBScript, do you understand the For Each...Next structure?

Avatar of glenn mastersglenn masters

ASKER

I'm not that far on VB script sorry I can just about read to understand but that's it I'm sorry.

I know it cheeky but would be a great help if the script I posted was amended

I'm not one of these lazy people it just I'm still learning very slowly

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of aikimarkaikimark🇺🇸

Does this PS script do what you need done?  If so, it would be best if you started learning PS by adding comments that document what is happening in the script.  That would be a far more productive solution than an expert translating it into another language that you also can't read.

Yeah I agree can I just ask what I save a ps script as I.e .cmd or something???  And I will start looking

ASKER CERTIFIED SOLUTION
Avatar of aikimarkaikimark🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Thanks I will look and try

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Thanks

FWIW this could be converted to CMD, but if you're happy, I'm happy. :)
VB Script

VB Script

--

Questions

--

Followers

Top Experts

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.