user453949
user453949

Reputation: 173

Convert 2 powershell script to vbscript

We have 2 powershell scripts. The first one is written for Copy the new Files from SAN to NAS storage and delete older files in destination, as follows:


$a = Get-ChildItem h:\destination
foreach($x in $a)
    {        $y = ((Get-Date) - $x.CreationTime).Days
        if ($y -gt 6 -and $x.PsISContainer -ne $True)
            {$x.Delete()}
    }

foreach ($i in Get-ChildItem k:\SourceFolder) { if ($i.CreationTime -gt ($(Get-Date).Adddays(-1))) { Copy-Item $i.FullName h:\destination\ } }

and the Second one is for running Windows ntbackup.exe to backup system state and delete older backup files


$date = ( get-date ).ToString('yyyyMMdd')

ntbackup backup systemstate /J "Backup Job 1" /F "C:\test\$date-backup.bkf"

$a = Get-ChildItem c:\test

foreach($x in $a) { $y = ((Get-Date) - $x.CreationTime).Days if ($y -gt 6 -and $x.PsISContainer -ne $True) {$x.Delete()} }

for security reason I want to use vbscript of these 2 codes for running on my servers. any suggestion we`ll be appreciated

Upvotes: 0

Views: 2974

Answers (1)

user847990
user847990

Reputation:

Do you really want to go backwards? Do you fully understand what the ExecutionPolicy is for and how to use it?

The execution policy is more or less for user protection against automated scripts. As the PowerShell Team puts it here,

PowerShell trust user input, and runs it as-is. ...Execution Policies are a user feature. Like seatbelts. It's best to keep them on, but you always have the option to take them off.

I don't follow how it can be "frightening" to set the execution policy? I consider it a bit more frightening to allow users access to the Internet :)

If you are worried about scripts being executed on the server in question, then protect the server by preventing who has direct and remote access to the server.

Upvotes: 2

Related Questions