[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Scripting Languages

27K

Solutions

20K

Contributors

A scripting language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Primitives are usually the elementary tasks or API calls, and the language allows them to be combined into more complex programs. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), embedded systems, as well as numerous games. A scripting language can be viewed as a domain-specific language for a particular environment; in the case of scripting an application, this is also known as an extension language.

Share tech news, updates, or what's on your mind.

Sign up to Post

In Powershell, I would like to rename a file called "9.pdf" at C:\Attachment\Folder to the following date format October 16, 2018.pdf....

Only after the following script has run, with the purpose of inserting the new script at the end of this script if possible..  
And, I would like for it to pull the Date from the Date input which is found in the following script..


Get-ChildItem 'C:\Attachment\Folder' -Filter *.pdf | Where-Object {$_.BaseName -ne '9'} | Remove-Item -Force

Function Select-DateForm {
[CmdletBinding()]
Param(
	[String]$Title,
	[String]$Prompt,
	[DateTime]$MinDate,
	[DateTime]$MaxDate
)
	Function Show-FormMain {
		Add-Type -AssemblyName System.Drawing
		Add-Type -AssemblyName System.Windows.Forms
		[System.Windows.Forms.Application]::EnableVisualStyles()

		$formMain = New-Object -TypeName System.Windows.Forms.Form
		$formMain.ClientSize = New-Object -TypeName 'System.Drawing.Size' -ArgumentList 250, 250
		$formMain.FormBorderStyle = 'FixedSingle'
		$formMain.MaximizeBox = $false
		$formMain.MinimizeBox = $true
		$formMain.Text = If ($Title) {$Title} Else {'Date Selection'}
		
		$labelPrompt = New-Object -TypeName System.Windows.Forms.Label
		$labelPrompt.Location = New-Object -TypeName 'System.Drawing.Point' -ArgumentList 16, 8
		$labelPrompt.AutoSize = $true
		$labelPrompt.Text = If ($Prompt) {$Prompt} Else {'Please select a date:'}
		$formMain.Controls.Add($labelPrompt)

		$monthCalendar = New-Object -TypeName 

Open in new window

0
Exploring ASP.NET Core: Fundamentals
LVL 12
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

I need a powershell script that will do the following.

1.  I have a powershell command that will read the subkeys of a mail profile
Get-ChildItem -Path HKCU:\Software\Microsoft\Office\15.0\Outlook\Profiles

Open in new window


The output of the subkeys are below...

Name                                Property
----                                      --------
cool Outlook Profile
Outlook Profile
outlook



2.  I need each of the subkeys into a variable, how do I do that in Powershell?

3.  After I have that answer, I would like to run the command for each subkey variable, inst.exe /u /service dmol /p "Variable=mailprofile"

I really appreciate the feedback!
1
Greetings Everyone
I am very new and green at python scripting and need some guidance.
I have a script that reads temperature data from 3 different sensors.
It is set to currently print that data to the terminal screen.
The script works OK, but the issue I have is the data gets printed to the screen with an overabundance of decimal places. I have come across a function to round that data to 1 or 2 decimal places, which is what I want.
Unfortunately I can't seem to get the syntax correct and the function fails to work as I need.

Here are the print commands currently:

# Get Temperature and print to screen
while True:
    print ("Pool Temp = ", read_temp(temp_sensor_1))
    print("Air Temp = ", read_temp(temp_sensor_2))
    print("Box Temp = ", read_temp(temp_sensor_3))
    time.sleep(2)   # Read every 2 seconds

Open in new window


That returns the following output:

Pool Temp = 51.0166
Air Temp = 51.355
Box Temp = 64.557

Open in new window


Waits 2 seconds and repeats until I kill the script.

What I am looking for is something like this:

Pool Temp = 51.1°F
Air Temp = 51.2°F
Box Temp = 64..6°F

Open in new window


I found a reference to using the str.format() syntax but have not been able to make it work correctly.
Any help would be greatly appreciated.

:)

-Bob
0
is there any method to get a list of AD users who are using weak passwords for windows 2012R2 domain.
0
Combine all .csv files into one file,
Input folder is C:\Temp1\Folder..
Output folder will be the same.
Thanks in advance.

Batch is preferred, otherwise poewrshell would be fine as well.
0
I would like to use a simple script  to delete all *.csv files found in C:\Temp1\...  except for one file called Output.csv

It would be in Batch, .ps1 or vbs..

Thanks in advance.
1
I would kind to use a script that will look at a specific folder and if there are any .csv files it should join them.
All the csv files have the exact number of positions separated by a comma
0
I would like to know the batch commands for the attached input file that will do the following.
When it sees 01-ABCDA, or 01ABCDB - in position 4 'and' if it sees either 01230c, or 01232 in position 100,
then  it will change the last character from whatever 3 digits it sees at the end of those lines, to a ,008.


This is the input script in a .csv file.

5,A,01234,01-ABCDA,Y,1251/2,1772345,,20181003,20181107,20181114,,1234567890000,COMP ACCOUNTS PAYABLE,123 ROAD WAY,,TREEWAY,FL,01234-5678,,,,1234564870004,Somewhere Warehouse,200 Treeview Court NW,,Everywhere,GA,12345-1234,,,018-441-5522,41245,ABCORPBC,,USD,N,,,,,,,,,,N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,00987894561230,01230c,152324,STEEL,,,,123.00,US,0.00,US,0.00,US,10.5000,0.0000,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,101
5,A,01234,01-ABCDB,Y,1251/2,1772345,,20181003,20181107,20181114,,1234567890000,COMP ACCOUNTS PAYABLE,123 ROAR WAY,,TREEWAY,FL,01234-5678,,,,1234564870004,Somewhere Warehouse,200 Treeview Court NW,,Everywhere,GA,12345-1234,,,018-441-5522,41245,ABCORPBC,,USD,N,,,,,,,,,,N,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,00987894561560,01232,152345,WOOD,,,,789.00,US,0.00,US,0.00,US,10.5100,0.0000,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,102
5,A,01234,67891,Y,1253/2,1775478,,20181003,20181107,20181114,,1234567890000,OTHERCOMP ACCOUNTS PAYABLE,123 ROAD WAY,,FOREST,TX,01234-5678,,,,1234564870004,Another Warehouse, 300 Apt View Court NW,Specific …
0
Hey Experts!  To keep a directory from filling up with backup files, I schedule this script to run once a month.  However during my testing, I noticed that the log file doesn't record what file(s) were deleted or if errors were encountered.  How do I record the outcome of the delete file action?  Thanks Experts.

cd "C:\tools\Scripts\Test"
forfiles /d -0 /c "cmd /c del /q /f @file"

Open in new window

0
Experts,

In a file I need to have the possibility to grep a pattern in the first or in the second column.  If found the entire line is returned.
Comes with it that that pattern is a variable.

Grepping the var in the first column is easy, but I can't get it to work for the second column (sep is >).

var=MSPROXML


MSUPDSEOT>MSPROXMLH
VSRFUMVTT>MSPROXMLH
FT0Y6600_T>MSPROXMLH
MSINSMSGT>MSPROXMLH
MSPROXMLT>XGGENEXTH
MSPROXMLT>CD0E0100_H
MSPROXMLT>FT0Y3600_H
MSPROXMLT>PC0R3420_H
MSPROXMLT>WO0A0020_H

This is what would need to be returned:

MSUPDSEOT>MSPROXMLH
VSRFUMVTT>MSPROXMLH
FT0Y6600_T>MSPROXMLH
MSINSMSGT>MSPROXMLH

Thank you for  your help.
Watnog
0
Introduction to R
LVL 12
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

In batch, check if a file type exists at a specific folder  
For example, if at C:\folder\file it sees any *csv file, it should rename it to File1.csv.
0
At the beginning of this powershell script, how can I specify on line 2, that if it finds either *.csv,, or  any file ending with.  rev1.csv, or any file ending with rev2.csv....
It will never find multiple files in the folder just either *.csv, rev1.csv, or *rev2.csv


$inFolder = '\\saved\data'
$outSuffix = '_rev1'

Open in new window




$outSuffix = '_rev'
0
In Powershell, how can I specify to look at a specific path, such as  C:\folder\files\....  and if it sees any files that end with either *.csv, or end/preceded by rev_csv, but leave other files intact?
0
I would like to modify the attached script so that when it sees 01-ABCDA, or 01ABCDB, 'and' if sees either 01230c, or 01232 in position 100, that it will change the last character from whatever 3 digits it sees at the end of those lines, to a ,008.

No other functions in the script are needed, so I am sure many of the lines will have to be removed.....

$inFolder = '\\saved\data'
$outSuffix = '_rev'


$referenceCount = 0
$row = 0
Get-ChildItem -Path $inFolder -Filter *.csv | Where-Object {$_.BaseName -notmatch "$($outSuffix)\Z"} | ForEach-Object {
	$outFile = Join-Path -Path $_.DirectoryName -ChildPath "$($_.BaseName)$($outSuffix)$($_.Extension)"
	$saveFile = $false
	Write-Host "Processing '$($_.Name)' ..."
	$content = Get-Content -Path $_.FullName | ForEach-Object {
		$fieldChanged = $false
		$row++
		$fields = $_.Split(',')
		If ($referenceCount -eq 0) {$referenceCount = $fields.Count}
		If ($fields.Count -ne $referenceCount) {
		   Throw "Field count in line $($row) is incorrect (is: $($fields.Count), expected: $($referenceCount))!"
		}
		$fields = $fields + ''
		$old3 = $fields[3]
		If ($addLastField.Keys -contains $fields[3]) {
			$fields[-1] = $addLastField[$fields[3]]
			$fieldChanged = $true
		}

		If ($fieldChanged) {
			Write-Host "    line $($row): $($old3) [$($fields[26])]) --> $($fields[3]); last: $($fields[-1])"
			$saveFile = $true
		}
		$fields -join ','
	}
	If ($saveFile) {
		$content | Set-Content -Path $outFile
		Write-Host "Changes written to 

Open in new window

0
Within a bat file, I want to call 2 or more .ps1 scripts and then return to the bat file after running each .ps1 script.
How can I do this within the .bat so that after calling and running on one .ps1 script, when that script is finished it will return to the .bat file to continue with other functions, including running another .ps1 file etc..
0
I'm using manage-bde.exe to allow some power user to encrypt their USB Stick.
I have a DC (Windows Server 2012 R2) with 100 hunder windows 10 pro laptpos.
The users don't have admin privlege on their machines.
I found that changing  WMI privilege manually  (ROOT>CIMV2>Security>MicrofostVolumeEncryption) and adding manually the specif account and giving him  "execute method" privilege allow the user to run the encryption without possessing admin rights.

I'm trying to create a script that I'm going to push via GPO to apply the needed changes.
I tried using this method  without success.
I can dump the privlege. Applying them give no errors but no changes are done.
Both operations are done with local admin account.
Thanks.
0
On a Redhat Linux system running a bash shell script I need some help with an if then statement that has more than 2 conditions. I basically want to check for this
A AND B or C  
A AND B or D
A AND B or E

Something along these lines but it doesn't work and wondered if I have the correct usage of brackets. It's not what's contained for evaluation that's the issue it's the syntax of the AND and OR where there's more than two conditions that I am struggling with.

if [[ $(find /opt/app -name httptd*.conf | grep -v grep | grep -c http) -eq 0 ] && [ ! -f /etc/init.d/apache ] ||  [ $(find /app -name http*.conf | grep -v grep | grep -c http) -eq 0 ]] || \
[[ $(find /opt/app -name httptd*.conf | grep -v grep | grep -c http) -eq 0 ] && [ ! -f /etc/init.d/apache ] ||  [ $(find /application -name http*.conf | grep -v grep | grep -c http) -eq 0 ]] || \
[[ $(find /opt/app -name httptd*.conf | grep -v grep | grep -c http) -eq 0 ] && [ ! -f /etc/init.d/apache ] ||  [ $(find /application -name manifest* | grep -v grep | grep -c http) -eq 0 ]] ; then
.....
0
Modify the PS Script below, sot that depending on what it sees in position 4, it will add a field.
For example:
If it sees 12345, it will add a ",100"
If it sees 67891, it will add a ".500"
(without the quotations).

[code][/$inFolder = '\\saved\data'
$outSuffix = '_rev'
$replace_67891 = @{
      'SPECIFIC PLACE' = '01-US'

}

$referenceCount = 0
$row = 0
Get-ChildItem -Path $inFolder -Filter *.csv | Where-Object {$_.BaseName -notmatch "$($outSuffix)\Z"} | ForEach-Object {
      $outFile = Join-Path -Path $_.DirectoryName -ChildPath "$($_.BaseName)$($outSuffix)$($_.Extension)"
      $saveFile = $false
      Write-Host "Processing '$($_.Name)' ..."
      $content = Get-Content -Path $_.FullName | ForEach-Object {
            $fieldChanged = $false
            $row++
            $fields = $_.Split(',')
            If ($referenceCount -eq 0) {$referenceCount = $fields.Count}
            If ($fields.Count -ne $referenceCount) {
                  Throw "Field count in line $($row) is incorrect (is: $($fields.Count), expected: $($referenceCount))!"
            }
            $old3 = $fields[3]
            If ($fields[3] -eq '67891') {
                  If ($replace_67891.ContainsKey($fields[26])) {
                        $fields[3] = $replace_67891[$fields[26]]
                        $fieldChanged = $true
                  }
            }

            If ($fieldChanged) {
                  Write-Host "    line $($row): $($old3) [$($fields[26])]) --> $($fields[3])"
                  $saveFile = $true
            }
            $fields -join ','
      }
      If ($saveFile) {
            $content | Set-Content -Path $outFile
            Write-Host "Changes written to $($outFile)."
      } Else {
            Write-Host "No changes found."…
0
is there an easy way via powershell to scan a text/log file (they have extensions of *.log or *.txt) and it return how many rows of data there are in it? I have some gigantic txt files which I am struggling to import into excel and access (may need to look at SQL Server) but knowing the number of rows of data upfront would help.
0
OWASP: Avoiding Hacker Tricks
LVL 12
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Hello, I am using AutoHotKeys (AHK) to make Control + P to paste the content of the clipboard and then immediately clear it. The idea is to not leave sensitive information such as passwords hanging around on the clipboard. Basic functionality using the script below is working OK:

; Paste and clear clipboard with Control + P
^p up::
send ^{v}
sleep 100
clipboard := ""
MsgBox, 0, Notice, Clipboard cleared, 1
return

But I am tryng to improve it in two ways:
1. Not have the message appear if there is nothing on the clipboard to be pasted (or alternatively have another message "Clipboard is empty" appear).
2. Remove the "OK" button from the message box (since the message autodisappears it is not needed)

Regarding 1. I have tried all sorts of If....Else variations but just cannot seem to get the condition for "empty clipboard" right.
Regarding 2. maybe this is just not possible going by AHK's documentation https://autohotkey.com/docs/commands/MsgBox.htm. But if anyone has alternative ideas they would be appreciated.

I am using the latest version of AHK ( v1.1.30.00 ) on Windows 10 Pro. Thank you in advance for any comments.
0
Experts, Looking for additional PowerShell scripting assistance

Function copy-File1 {
Param(
	[Parameter(Mandatory=$true)]
	$FileName
)
	#Drive Locations
	$tempDir = "$($locations.tempdir)"
	$WorkingDir = "$($locations.working_Dir)"
    $tdrivedir = "$($locations.tdrivedir)"
	[string]$filenamenew = "$(&$filenames.cwf_FileNameNew)"
    [string]$Destination = "$(&$filenames.cwf_Destination)"
    [string]$WorkFileloc = "$(&$filenames.cwf_WorkFileLoc)"
	
	#filename Trim
	$FileName = $FileName.Trim()
	If ([string]::IsNullOrEmpty($FileName)) {
		Throw 'Argument FileName is empty!'
	}
	$filePath = Join-Path -Path $tempDir -ChildPath $FileName
	#Identify which File is being Processed
	Write-Host -ForegroundColor Green "Processing File ""$($filePath)"" ..." -NoNewline
	#Test File Destination Path to see if File Exists.. If it Exists Remove it
	If (Test-Path -Path $filePath) {
		Write-Host " $($filePath) Already Exists : Removing File From Temp Location" -NoNewline
		#Error Handling for Remove-Item Command
		Try {
			$itemtemp = Get-Item -Path $filePath -ErrorAction Stop
 			Remove-Item $itemtemp -ErrorAction Stop
			Write-Host -ForegroundColor Green " Successfully Removed File $FileName" -NoNewline
		
		#Add Error Handing for Copy Command
			Write-Host -ForegroundColor Green "Setting $($workingdir) location"
			Set-Location $WorkingDir;
			if (Test-Path -Path $workingdir){
				Try {
					Write-Host -foregroundcolor green "Path Successfully set to $($workingdir)"
					

Open in new window

0
I found a usefulPowerShell script online (full code below) which helped me review an enormous txt file (log file) for rows containing a key word phrase and output just those rows to a txt file. What I could do with is a way of amending the $pattern row below:

$pattern = ‘searchterm’

Open in new window



..to search another text file I have created which contains for a number of search terms I have put together, rather than me having to run the command for every search phrase I need to check individually.

full code:

$inFile = '\\server\share\directoruy\file.txt'
$outFile = '\\server\share\directoruy\hits.txt'
$pattern = ‘searchterm’
Select-String -Path $inFile -SimpleMatch $pattern | Select-Object -ExpandProperty Line | Set-Content -Path $outFile

Open in new window


for info the format of the text file I have created for using is just in a row by row format, e.g

searchphrase1
searchphrase2
searchphrase3
1
What is the BCC command used for VBS script when compiling an email?
0
I would like to add BCC addresses to a program called System Scheduler.

https://www.splinterware.com/products/scheduler.html

Is this possible?
0
I would like to see a sample VBS and Batch script that will send from a gmail account using port 587, with an attachment.
0

Scripting Languages

27K

Solutions

20K

Contributors

A scripting language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Primitives are usually the elementary tasks or API calls, and the language allows them to be combined into more complex programs. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), embedded systems, as well as numerous games. A scripting language can be viewed as a domain-specific language for a particular environment; in the case of scripting an application, this is also known as an extension language.