Wednesday, May 15, 2024

[WSRV] Powershell History from other sessions

 


(Get-PSReadlineOption).HistorySavePath

or


Get-Content (Get-PSReadlineOption).HistorySavePath | more


or 


notepad (Get-PSReadlineOption).HistorySavePath

Friday, March 15, 2024

[O365] Send email in O365 via Powershell

 

$Recipient = "contact@domain.com"

$Subject = "Hello, World!"

$Body = "This is the body of the email."

$credentials = Get-Credential

Send-MailMessage -To $Recipient -Subject $subject -Body $body -From $credentials.UserName -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential $credentials


-----------------


Using saved/exported password:


# $credentials.Password | ConvertFrom-SecureString | out-file  L:\Downloads\senha.sec

$sen = Get-Content L:\Downloads\senha.sec | ConvertTo-SecureString

$us = "sender@mydomain.com"

$em = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $us,$sen

Send-MailMessage -To $Recipient -Subject $subject -Body $body -From $us -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential $em

Sunday, February 25, 2024

[WSRV] Import private key into certificate file

 

openssl pkcs12 -export -out cert.pfx -inkey private.key -in cert.crt -certfile CACert.crt

Wednesday, February 7, 2024

[WSRV] Check Hyper-V VMs Paths


List Checkpoint, Configuration and Snapshot File Locations:

 

get-vm  | select id,name,*location | ft -AutoSize


List the HardDrives attached into the Virtual Machines


get-vm | Get-VMHardDiskDrive | sort Path | select vmname,Path

Thursday, November 9, 2023

[EX16] Send test message with attachment

 fsutil file createnew c:\filess\FILE19.xlsx 1909900


$file = "c:\filess\FILE19.xlsx"


$mn = 2


do {

$id =  "$mn"+' - Test Message #'+$mn

$id

$mn--

(Get-Mailbox zez*) | % {Send-MailMessage -SmtpServer (Get-ExchangeServer).Fqdn -To $_.primarysmtpaddress -From admin@domain.com -Subject $id -Body "ATTACHMENT TO FILL UP THE MAILBOX" -attachment $file}

}while($mn -gt '0')

Wednesday, November 1, 2023

[EXO] Collect Failures of Sync Requests

 start-transcript

$syncstats = Get-SyncRequestStatistics user@domain.com  -IncludeReport -DiagnosticInfo verbose

$syncstats.Report.Failures | group failuretype

$syncstats.Report.Failures | select -last 2

$syncstats.Report.InternalFailures

$syncstats.DiagnosticInfo

$syncstats.Report.Entries | % {[string] $_}

stop-transcript

[EXC] Convert Values to GB

 =LEFT(B2,LEN(B2)-2)/10^((MATCH(RIGHT(B2,2),{"PB","TB","GB","MB","KB"},0)-3)*3)



to MB, handling error


=IFERROR(LEFT(D2,LEN(D2)-2)/10^((MATCH(RIGHT(D2,2),{"PB","TB","GB","MB","KB"},0)-4)*3),0)