Tuesday, January 14, 2025

[WSRV] Save Credentials for Remote Desktop

 

cmdkey /generic:TERMSRV/192.168.0.11 /user:192.168.0.11\administrator /pass:passw0rd

Thursday, January 2, 2025

[EXCH] Collect Schema and Object versions

 # Exchange Schema Version

$sc = (Get-ADRootDSE).SchemaNamingContext

$ob = "CN=ms-Exch-Schema-Version-Pt," + $sc

Write-Output "RangeUpper: $((Get-ADObject $ob -pr rangeUpper).rangeUpper)"


# Exchange Object Version (domain)

$dc = (Get-ADRootDSE).DefaultNamingContext

$ob = "CN=Microsoft Exchange System Objects," + $dc

Write-Output "ObjectVersion (Default): $((Get-ADObject $ob -pr objectVersion).objectVersion)"


# Exchange Object Version (forest)

$cc = (Get-ADRootDSE).ConfigurationNamingContext

$fl = "(objectClass=msExchOrganizationContainer)"

Write-Output "ObjectVersion (Configuration): $((Get-ADObject -LDAPFilter $fl -SearchBase $cc -pr objectVersion).objectVersion)"

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