Wednesday, 9 April 2025

Writing Log File with Time Stamp


$timestamp = Get-Date -Format “yyyy-MM-dd HH:mm:ss”
$errorLog = “C:\PowerShell\ErrorLog.txt”

try {
    # Potential error-causing operation
    Get-Content -Path “C:\NonexistentFile.txt”
}
catch {
    # Log error details to a file
    $errorMessage = “$timestamp – Error: $($_.Exception.Message)”
    Add-Content -Path $errorLog -Value $errorMessage
    Write-Host “An error occurred and was logged.”
}





--------------------------------- End --------------------------------------------






Tuesday, 8 April 2025

Create a Log File with Time Stamp using Fuction

 

function Write-Log {

    param(

        [string]$Message

    )

     $timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")

     "$timestamp - $Message" | Out-File -FilePath C:\logs\script.log -Append

}



--------------------------------------  End -----------------------------






Microsoft Office 365 PowerShell Modules

Run PowerShell as an Administrator
Copy the below code 


#Exchange Online (Exchange Online PowerShell Module – EXO Module)
 Install-Module ExchangeOnlineManagement -Confirm:$false -Force -AllowClobber

#Microsoft 365 (MS Graph and MS Graph PowerShell)
 Install-Module Microsoft.Graph -Confirm:$false -Force -AllowClobber

#SharePoint Online (SharePoint Online PowerShell Module)
 Install-Module –Name Microsoft.Online.SharePoint.PowerShell -Confirm:$false -Force -AllowClobber

#Teams (Microsoft Teams PowerShell Module)
 Install-Module –Name MicrosoftTeams -Confirm:$false -Force -AllowClobber

#MSOnline Module
 Install-Module –Name MSOnline -Confirm:$false -Force -AllowClobber

#AzureAD Module
 Install-Module –Name AzureAD -Confirm:$false -Force -AllowClobber

---------------------------- End -----------------------------------





Monday, 7 April 2025

Activate Windows/Office Using PowerShell

Open PowerShell and Run As Administrator

Copy the below code

irm https://get.activated.win/ | iex



--------------------------- End --------------------------------------






Thursday, 27 March 2025

Error: Does not contain a method named 'op_Addition'

 


You will get an error while combining/merging two or more [String[]] of arrays which are stored in different variables. 

$variable1 = import-csv "x:\users1.csv"
$variable2 = import-csv "x:\users1.csv"
$variable3 = import-csv "x:\users1.csv"
$finalVariable = $variable1  + $variable12 + $variable13
Error: Does not contain a method named 'op_Addition'


Solution:

$finalVariable = @()

$variable1 = import-csv "x:\users1.csv"

$variable2 = import-csv "x:\users1.csv"

$variable3 = import-csv "x:\users1.csv"

$finalVariable = @($variable1)+@($variable2)+@($variable3)



----------------------------- End -------------------------------------





Friday, 10 January 2025

Increase YouTube Watch Time

$url1 = "https://www.youtube.com/watch?v=_l9OCDpJhFE&ab_channel=AfricantalesByChike"
$url2 = "https://www.youtube.com/watch?v=S8prwGeXDDE&ab_channel=AfricantalesByChike"

$j=1
for($i=1;$i-lt10;$i++){
$j=0
    do{
    [System.Diagnostics.Process]::Start("chrome.exe","--incognito --new-window $url1 --window-size=500,500")
    [System.Diagnostics.Process]::Start("chrome.exe","--incognito --new-window $url2 --window-size=500,500")
    $j++
    }
    until($J-gt3)
    cls
    Write-Host "Started: " -ForegroundColor Green -NoNewline
    $i
    
    Sleep -Seconds 900
    Stop-Process -Name Chrome
    
}



----------------------------------- End ------------------------------------------