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

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)




[O365] Collect more than 1000 results in Message Trace

 $P = 1

$messages = $null

do

{

Write-Host “Message Trace – Page $P…”

$temp_Messages = Get-MessageTrace -startdate "09/12/2022 12:00:00 AM" -Enddate "09/12/2022 06:00:00 PM" -PageSize 1000 -Page $P

$P++

$Messages += $temp_Messages

}until ($temp_Messages -eq $null)


#display messages

$Messages.Count

$Messages

Thursday, October 12, 2023

[WSRV] Remote Connection saved credentials via powershell

 

To list saved credentials:

cmdkey /list:TERMSRV/*

To delete a saved credential:

cmdkey /delete:TERMSRV/<targetNameOrIp>

To add a credential that will actually work with CG turned on:

cmdkey /generic:TERMSRV/<targetNameOrIp> /user:<username> /pass:<password>

Cmdkey

Friday, May 8, 2020

[LY15] Check user's response group



Get-CsRgsAgentGroup | Where {$_.AgentsByUri -Like “*risual.user*” | FT Name  

Monday, March 30, 2020

[O365] Export reports for quarantined messages



Get-QuarantineMessage | select ReceivedTime,SenderAddress,RecipientAddress,Subject,Type,SystemReleased,PolicyType,Expires | Export-CSV -NoTypeInformation “c:/reports.csv”

Wednesday, October 16, 2019

[WSRV] Check Hyper-V Host



(get-item "HKLM:\SOFTWARE\Microsoft\VirtualMachine\Guest\Parameters").GetValue("HostName")

Monday, January 14, 2019

[WSRV] Search for file with a special character in the file name?



~="("

~="&"

~="hello you (1"

[WSRV] AVMA Keys


slmgr /ipk <AVMA_key>  



AVMA keys

The following AVMA keys can be used for Windows Server 2019.
EditionAVMA key
DatacenterH3RNG-8C32Q-Q8FRX-6TDXV-WMBMW
StandardTNK62-RXVTB-4P47B-2D623-4GF74
Essentials2CTP7-NHT64-BP62M-FV6GG-HFV28
The following AVMA keys can be used for Windows Server, version 1809.
EditionAVMA key
DatacenterH3RNG-8C32Q-Q8FRX-6TDXV-WMBMW
StandardTNK62-RXVTB-4P47B-2D623-4GF74
The following AVMA keys can be used for Windows Server, version 1803 and 1709.
EditionAVMA key
DatacenterTMJ3Y-NTRTM-FJYXT-T22BY-CWG3J
StandardC3RCX-M6NRP-6CXC9-TW2F2-4RHYD
The following AVMA keys can be used for Windows Server 2016.
EditionAVMA key
DatacenterTMJ3Y-NTRTM-FJYXT-T22BY-CWG3J
StandardC3RCX-M6NRP-6CXC9-TW2F2-4RHYD
EssentialsB4YNW-62DX9-W8V6M-82649-MHBKQ
The following AVMA keys can be used for Windows Server 2012 R2.
EditionAVMA key
DatacenterY4TGP-NPTV9-HTC2H-7MGQ3-DV4TW
StandardDBGBW-NPF86-BJVTX-K3WKJ-MTB6V
EssentialsK2XGM-NMBT3-2R6Q8-WF2FK-P36R2

Saturday, January 12, 2019

[EX16] Script to send test message with attachment


Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
$file = "C:\Users\admin\Desktop\f2.zip"
get-mailbox -organizationalunit "formula one" | % {Send-MailMessage -SmtpServer exhub.domain.int -To $_.primarysmtpaddress -From senna@domain.com -Subject “SUBJECT HERE” -Body “BODY HERE” -attachment $file}

[EX16] Correct UPN to match Smtp


$ggg = Get-Mailbox -OrganizationalUnit "formula indy"
$ggg | % {Set-Mailbox -Identity $_ -UserPrincipalName  $_.primarysmtpaddress}

Thursday, January 3, 2019

[WSRV] Powershell Cmdlets - Network



Test-NetConnection -ComputerName "Hostname or IP"

Test-NetConnection "Hostname" -Port #

Test-NetConnection "Hostname" -traceroute

Get-NetIPConfiguration

Resolve-DnsName -Name "Hostname"

Get-NetTCPConnection

Get-DnsClient
Set-DnsClientServer Address

Clear-DnsClientCache


Disable-NetAdapter -Name "Adapter Name"
Enable-NetAdapter -Name "Adapter Name"