Skip to main content


Showing posts with the label Startup Script

Compare multiple variables Conditions with if else in PowerShell

Multiple conditions to evaluate is sometimes necessary in order to decide whether the script should continue to execute a specific command or do another process.

PowerShell is able to do this kind of task using if else statement.

Example script below just shows 3 variables that should match and it will output "OK", the output is just a write-host command but it could be replaced with other codes.

And if one of the statements does not match the "else" statement is executed.Example code: All statements or condition matches

$var1="Online"$var2="Running"$var3="Proceed"if (($var1-eq"Online") -and ($var2-eq"Running")-and ($var3-eq"Proceed")) {write-host"OK"} else {write-host"Not OK unable to Proceed"}

Python check if an item is on the list

How to check whether an item exist on the list?
If then else and using the "in" operator in Python is able to check whether an item is on the list or not.
Here's a code example, it's not a complete program but a demonstration how the snippet can be used, the code can be integrated into an existing complete code.
lst = list() #list declaration in Python      #if item is already on the list it will just continue and will not execute the else command            if yitem in lst: continue          else:           print(" Item 'yitem' is not present in the list, appending item to the list.")           lst.append(yitem)  #action that will be done if item was not found on the list
For completeness sake if something needs to be done if the item is found, then the code will be like this:
       if yitem in lst:             print "Item is found and is present on the list."          #do something more if required        else:           print(" Item 'yitem&…

Read or get the list of contents on S3 bucket

S3 or Simple Storage Service bucket is quite handy to store files or any data on AWS cloud.As with any storage, online or offline organizing the data is quite an issue.When there are a lot of files of data on the storage; finding the data that you will need will be difficult. Especially, if the data or bucket is not organized properly. And even if the data has been organized by folders with proper time stamp but no specific data catalog to classify which one is which one it is quite a challenge to find or get the data on time.S3 is ideal for backup, since backup is often accessed only when it is needed. So, familiarization of the backup folder structure is necessary. In order to find or get easily the data, listing the contents of the S3 bucket is a good option when unable to find the files or data needed.Once the list is ready, opening the list via editor such as notepad and searching or finding thru the editor will provide an option to find things quickly and easily.
How to list the …

PowerShell launch an application and close it automatically

Code below will run an application and PowerShell will also close it after a few seconds.$process_id=Invoke-CimMethodWin32_Process-MethodName"Create"-Arguments @{CommandLine ='cmd /c "C:\dev\remind.bat"'} |Select-Objectprocessid|ft-HideTableHeaders|Out-StringStart-Sleep-Seconds2.5stop-process$process_idSample contents of remind.bat:
@echo off
echo "Shutdown the server. Do it now."
==================Notepad is on the batch file so the command window will stay on the top of any running applications.Sample output of the above code:
Code below will run calculator and close after a few seconds specified on the code:Invoke-CimMethodWin32_Process-MethodName"Create"-Arguments @{CommandLine ='calc.exe'} |Select-Objectprocessid|ft-HideTableHeaders|Out-StringStart-Sleep-Seconds2.5$get_process_id=Get-Process-Namecalcu*|<

PowerShell get startup items or files

Checking startup items or files, when Windows is starting or upon user successful login is quite important.
Some files need to run on startup so it can be used while the user or computer is being in used.
Or the startup files is set, so when the computer starts the file or items will also start. In this way, you don’t have to remember what things to open when the program or items will run during startup.
Of course, it’s not only the important files will be set during startup. Some viruses or malware sometimes use this method to load the software, so that they will also be in the system as long as the user is logged in.
So, how to check in PowerShell to get all those startup items or files?
Here’s the code:
Sample output:
Description : OneDrive Command: "C:\Users\duser_name\AppData\Local\Microsoft\OneDrive\OneDrive.exe" /background Location: HKU\S-1-5-21-abcdef-007-corona-2020\SOFTWARE\Microsof…