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