Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Passing Arguments against scripts to find reserved characters

$
0
0

First, thanks to Don Jones and the community! Fair warning... I'm still a n00b when it comes to powershell.... still learning.. So if I have spaghetti code, my apologies.Big Smile

What I'm trying to accomplish is to take reserved characters and pass each character against various scripts. I.E *.js, *.vbs, *.vbe, *.bat, *.msi etc...  I want to pass a character to a script and then print to a log of what character it errors on. So if I pass a % against a script and it errors... log it, if no error log that as a success.

For Example: cscript.exe /NoLogo .\script.js %

Right now I'm working on passing arguments to a javascript file but seems to be failing with the following error: "Input Error: There is no script engine for file extension ".$jscode()) $JScriptArgs"."

Found some help from: https://devcentral.f5.com/blogs/us/powershell-abcs-j-is-for-javascript

Updated Code to reflect changes within past few hours of me working on it!

#############

# Variables
####################################
$CurrentDir="C:\scripts\testing"
$LogPath="$CurrentDir\logs"

####################################
# Functions
####################################
#JavaScript
functionCreate-ScriptEngine()
{
param([string]$language=$null, [string]$code=$null);
if ( $language )
{
$sc=New-Object-ComObject ScriptControl;
$sc.Language=$language;
if ( $code )
{
$sc.AddCode($code);
}
$sc.CodeObject;
}
}


####################################
####################################

####################################
# Global
####################################
#Clears out error var
#$error.Clear()


######
# JavaScript
######
$jscode= @"
function Hello()
{
alert("Hello World!")
}
"@
$JSCreate=Create-ScriptEngine"JScript"$jscode
$JScriptArgs=Get-Content ("$CurrentDir\chars.txt")
[string]$JScriptCommand=cscript.exe/NoLogo '$JSCreate.$jscode() $JScriptArgs'

ForEach ($jsin$JScriptArgs)
{
Invoke-Command-ScriptBlock {$JScriptCommand}
Write-Host"Testing JavaScript Argument: $js"-ForegroundColor Green
Add-Content-Path"$LogPath\JScript.log"-Value$js-PassThru
}
# Creates log of actions
$error | Out-File C:\scripts\testing\logs\JScript-Error.log

######
# VBS
######
$VBSArgs=Get-Content ("$CurrentDir\chars.txt")
$VBSCommand= cscript /B /NoLogo '$CurrentDir\test3.vbs'$VBSArgs

ForEach ($vbsin$VBSArgs)
{
Invoke-Command-ScriptBlock {$VBSCommand}
Write-Host"Testing JavaScript Argument: $vbs"-ForegroundColor Green
Add-Content-Path"$LogPath\VBS.log"-Value$vbs-PassThru
}
# Creates log of actions
$error | Out-File C:\scripts\testing\logs\VBS-Error.log

######
# VBE
######
$VBEArgs=Get-Content ("$CurrentDir\chars.txt")
$VBECommand= cscript /B /NoLogo "$CurrentDir\test3.vbe"$VBEArgs

ForEach ($vbein$VBEArgs)
{
Invoke-Command-ScriptBlock {$VBECommand}
Write-Host"Testing JavaScript Argument: $vbe"-ForegroundColor Green
Add-Content-Path"$LogPath\VBE.log"-Value$vbe-PassThru
}
# Creates log of actions
$error | Out-File C:\scripts\testing\logs\VBE-Error.log

Viewing all articles
Browse latest Browse all 8411

Latest Images

Trending Articles



Latest Images