Skip to main content


Showing posts with the label Windows

PowerShell Get OneDrive email address

If you have a subscription to Office 365, chances are you have OneDrive configured in your system and is linked to your email address.
OneDrive is quite good since you can have your data on the cloud, of course you also have to use common sense and what data you are uploading to the cloud.
OneDrive will come handy since you just need internet connection and you will be able to retrieve your notes or data anywhere.
But how to check which email address is linked to your OneDrive? Well, there' a simple way using PowerShell to view registry keys.
A one liner PowerShell script will come-in handy to do these kind of task.
Here’s the code, if using Hotmail, or Live email:
For OneDrive Business use this code:


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:
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

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…

How to check 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…

PowerShell remove spaces or trim leading and trailing space

In PowerShell, removing a space or multiple white lines is an easy task.

Below are two methods on how to remove trailing, leading or just simply remove any space found on a string or variable.

Here's the code and example, with its image output:

#Method 1
$string_with_spaces= "    I am a string with with leading and trailing space     "
$count_the_characters = $string_with_spaces.Length
write-output ("Number of characters before trim: " + $count_the_characters) 

The PowerShell script: #Method 1 $string_with_spaces= "    I am a string with with leading and trailing space     "
$var_string_no_space = $string_with_spaces.trim()

Write-Output $var_string_no_space
$count_the_characters = $var_string_no_space.Length
write-output ("Number of characters after trim: " + $count_the_characters) 
Here's the output and the number of characters after trimming the space.

Before removing or trimming the string there were 59 characters, from above image after remov…