Skip to main content

Posts

Showing posts from April, 2020

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:
Get-CimInstanceWin32_StartupCommand|selectDescription,Command,Location,User,Caption
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…

PowerShell get time zone setting

Time zone settings in computers has a lot of purposes, of course it can tell you the time when to knock off from work. 😊 But there’s a lot of other purposes and having a time zone that is different from software application that is expecting, then unexpected issues may arise.

Database must be in sync with a correct time zone or else time stamp on database records will be inaccurate, system logs must also be in a correct time zone or else when diagnosing the logs or data will be an issue. There are other issues that requires to have a correct time zone setting set on your computer. Checking whether the correct time zone is set on your computer can easily be done in PowerShell.
So, how to get time zone settings in PowerShell?
Here’s the code:
Get-CimInstanceWin32_TimeZone|selectcaption
Windows 10 does support a setting with multiple time zone, here’s an output from above PowerShell with two time zone set on a computer.
Sample output:
caption ------- (UTC+08:00) Kuala Lumpur, Singapore


C…

Get PowerShell version on remote computers

PowerShell version on remote computers must be installed with the latest version if possible. It would make life easier.
New version comes with of course, new features and more fun. And if all servers or PCs has the same PowerShell version, then you need to create one version of PowerShell that works for all computers or servers.
But how to get PS version on remote computers?
To get the version locally, it’s quite straight forward:
Method 1: ($Psversiontable).PSVersion
Method 2:
(get-host).Version
To get version on remote computers, just add a few lines from the command above.

#--------- save as Get_PS_Version.ps1 or any file name $xversion= (get-host).Version $xversion_output="PowerShell Version: "+$xversion
$pc_name=$env:computername $pc_output="Computer Name: "+$pc_name

$xversion_output+"`n">>c:\scripts\output\$pc_name.txt $pc_output>>c:\scripts\output\$pc_name

How to check office version from command line

The are quite a few ways to check office version it can be done via registry, PowerShell or VBScript and of course, good old command line can also do it.
Checking Windows office version whether it is Office 2010, Office, 2013, Office 2016 or other version is quite important to check compatibility of documents; or just a part of software inventory.
For PowerShell this simple snippet can check the office version:
$ol=New-Object-ComObjectExcel.Application $ol.Version
The command line option will tell you where’s the path located; the result will also tell whether office is 32-bit, 64-bit and of course the version of the office as well.
Here’s the command that will check the office version and which program directory the file is located which will tell whether it’s 32-bit or 64-bit.
Command to search for Excel.exe:
DIR C:\ /s excel.exe | find/i "Directory of" 
Above command assumes that program files is on  C: drive.
Sample Output, if 64-bit version:
Directory of C:\Program Files\…

PowerShell with regex to rename files

Renaming files is quite an easy task but if the files to be renamed are about 100 files or more then you have to think twice and is not fun doing repetitive simple task.

Anyway, PowerShell is handy for this kind of task.
Regex in PowerShell is helpful in order to filter only matching files that needs to be renamed and leave any other files that doesn’t need  to be changed.
Example filename is like this: SampleTestData1_2019Result.csv
New desired filename would be:SampleTestData1_2020.csv
PowerShell code with regex to rename matching files.

How to use basic regex in PowerShell? The code below is a simple one.
Get-ChildItem-Path"c:\dev"|Where-Object {$_.BaseName -Match'2019.*'} | Rename-Item-NewName {($_.BaseName -Replace '2019.*','2020')+$_.Extension}
#'2019.*' – is the regex that matches 2019 until the end of the string #'2019.*','2020' – replace the match string with 2020
* = in regex match any character or basically don't ca…

WMIC command get CPU Load Percentage

Getting CPU load percentage is quite helpful in determining whether the server or computer is on a heavy performance, this would also indicate whether there is a need to increase the memory or add another CPU to the machine.

Of course, when the CPU has a lot of load, performance will be impacted directly. Which basically means that the machine will not be working perfectly.
Checking the CPU load will also help to troubleshoot, if the services on the machine or server is experiencing slow performance.
Here’s the wmic command line which check the CPU Load Percentage.
wmic cpu list status

Sample output: AvailabilityCpuStatusCurrentVoltageDeviceIDErrorCleared 319CPU0
ErrorDescriptionLastErrorCodeLoadPercentageStatusStatusInfo 15OK3

The command can be used to monitor remote servers or computers to check the load percentage and just save the output to a text file for review or monitoring purposes.

Cheers..Till next time. Hope it helps. 😊

================================ Free Android Apps:
Clic…

Excel VBA copy and paste a value or data

Copying and paste in Excel is quite simple and straight forward.
It should be the same thing with VBA, there are few ways to do this via VBA.
The simple is to record a Macro then check the code, then alter the data to suits the operation that needs to be done.
Basically, when copying and paste; it’s like pointing the data to another cell or cells so both locations will have the same value or data.
The code example below, does the above strategy. Get the value of the data that is to will be copied and point the data to a location where the data will be pasted.

Here's the Excel Vba code to copy and paste:

Sub CopyandPaste()
Set wb2 = ThisWorkbook
'Copy or set the value to be copied to a variable string_row_value = wb2.Sheets("Sheet1").Cells(1, 1).Value
'Paste or set the value to Sheet2 wb2.Sheets("Sheet2").Cells(1, 2).Value = string_row_value
'If needs to be copied to the same worksheet or in sheet1 itself 'Basically just define sheet name and the locati…

PowerShell Date Formatting

How to format a date in PowerShell?
There are a lot of methods to do this and two easy way, the easy or the hard way.
Easy way are the methods below:
#Method 1 $year = (get-date -UFormat "%D") Write-Output ("Method 1: " + $year + "`n`r")
#Method 2 $year = (get-date -UFormat "%m-%d-%y") Write-Output ("Method 2: " + $year + "`n`r")
#Method 3 $year = (get-date -UFormat "%d-%m-%y") Write-Output ("Method 3: " + $year + "`n`r")
#Method 4 $year = (get-date -UFormat "%d/%m/%y") Write-Output ("Method 4: " + $year + "`n`r")
Sample output: Method 1: 04/23/20
Method 2: 04-23-20
Method 3: 23-04-20
Method 4: 23/04/20
Image output below:



Cheers. Till next time. Hope it helps. :)

================================ Free Android Apps:
Click  links below to find out more:
Excel Keyboard guide: https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide

Heaven's Dew Fall  Prayer ap…

How to check or find unattached snapshot in AWS?

Checking unattached snapshot is a good technique to save some storage cost; of course, you need to do what’s the best thing after checking unattached snapshots.

If you are confident that the snapshot won’t be needed anymore, then it has to be deleted or else you will be incurring costs for nothing.
Every space on the cloud is not free, any space usage is an added cost to your pocket.But then how do you check for unattached snapshot in AWS?
There are quite a lot of ways you can do, if you love PowerShell it can be done in PowerShell; if you want to do it in Python with Boto3 it can be done as well.
Of course, in PowerShell and Python if this is the preferred method then you need to create some code. It won’t just spit out for you what are the unattached snapshots in your AWS account.
Enough said, the easiest way to search or look for unattached snapshot is just to search using the AWS EC2 console.
Open your browser, login to your EC2 console and search for: vol-ffffSee image below: vol-ffff w…