Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Help to Convert Powershell Script to VBScript

$
0
0

The script below is meant to find all PST files in my documents folder of any given logged on user and move the PST file to a location with enough space and reattach these PST files after they've been moved it appears to work so far. The script is meant to be run in Powershell but some computers in the organization don't have powershell installed so I need help converting the script to VBScript. Thanks

Background

Folder redirection has been applied to the My Documents folder but we haven't been able to device a work around to prevent PST files from being redirected as well and because filescreening has been implemented on our file server PST files are getting lost in transition.

#$docpath -- path for the user's my documents

$docpath=[Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments)

#$username -- username of current user

$username=[Environment]::UserName

#$altpath -- list of available fixed disks that archive can be stored with at least 8GB of free space

$altpart=[System.IO.DriveInfo]::GetDrives()|Where-Object {$_.Name-ne"C:\"-and$_.TotalSize-ge50000000000-and$_.AvailableFreeSpace-gt8000000000}

#$partname -- selected disk that archive would be moved to

$partname=$altpart.Name|Select -First1

$movepath=$partname+"Mails\"+$username

 

#Check recursively anytime a process starts to confirm it's outlook and closes it if it is

Register-WmiEvent–class"Win32_ProcessStartTrace"–sourceIdentifier"Process Started"-actionCloseOutlook

 

#Function to CloseOutlook

FunctionCloseOutlook

{

   Clear-Host

   $process=Get-ProcessOutlook-ErrorActionSilentlyContinue

   if ($process-ne$null)

    {

       $process.Kill()

       [System.Windows.Forms.MessageBox]::Show("System is backing up Outlook, Do not Open Outlook, Outlook would open automatically after it's finished")

    }

}

#Function to Move PST

FunctionMovePST

{

   CloseOutlook

   Get-ChildItem-Recurse-Path$docpath|Where-Object {$_.Extension-eq".pst"}|ForEach-Object {

  

        $nextName=Join-Path -Path$movepath -ChildPath$_.name

   

        while(Test-Path-Path$nextName)

        {

       $nextName=Join-Path$movepath ($_.BaseName+"_$num"+$_.Extension)   

        $num+=1  

        }$_| Move-Item-Destination $nextName-ErrorAction Stop  

     }

}

 

#Function to Add Stores back in

FunctionAddStores

{

   $Outlook=New-Object-ComObjectOutlook.Application

   #$ns = $ol.getNamespace("MAPI")

   $ns= $Outlook.getNamespace("MAPI")

   dir$movepath-filter*.pst|%{$ns.AddStore($_.Fullname)}

}

 

#When there's an available Fixed Disk with enough storage

if($partname-ne$null)

{

   if((Test-Path$movepath)-eq0)

    {

       cd$partname;

       cd"\";

       md$movepath;

       MovePST

       AddStores

    }

   elseif((Test-Path$movepath) -eq1)

    {

       cd$partname;

       cd"\";

       MovePST

       AddStores

    }

}

elseif($partname-eq$null)

{

   $partname="C:\"

   

    if ((Test-Path$movepath) -eq0)

    {

       cd$partname;

       cd"\";

       md$movepath;

       MovePST

       AddStores

    }

   

    elseif ((Test-Path$movepath) -eq1)

    {

       cd$partname;

       cd"\";

       MovePST

       AddStores

 

    }

}

A kind note I'm fairly new to scripting so the I'm sure this script leaves a lot to be desired.

Thanks Again


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>