Thursday, May 22, 2025

Script Sharepoint

 $shares = Get-WmiObject -Class win32_share -ComputerName (hostname)| ? {$_.name -notlike "*$*"}


$shares | % {

$sharePath = ($_.__PATH).replace("root\cimv2:Win32_Share.Name=","")

$sharePath = $sharePath.replace("""","")

$_ | Add-Member -Name SharePath -Value $sharePath -MemberType NoteProperty -Force

$_ | Add-Member -Name Servidor -Value $_.__Server -MemberType NoteProperty -Force

$_ | Select Name,Path,SharePath,Servidor | Export-Csv C:\temp\SharesNow.csv -Append -Notype

}


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