Posted On February 8, 2020

PowerShell: Some Tricks in Using the Here-String to Declare Blocks of Code

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Some Tricks in Using the Here-String to Declare Blocks of Code

Trigger COMMAND CLI from within PowerShell

# Fastest way to list all files in a directory. Bar none.
$getFiles = @"
cmd.exe /C dir '$source' /S /B /W /A:-D
"@
$files = Invoke-Expression -Command:$getFiles;

Loading a dotNet class into PowerShell

# Setting Powershell to skip SSL certificates checking
$classTrustAllCerts = @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate,WebRequest request, int certificateProblem) {
return true;
}
}
"@
Add-Type -TypeDefinition $classTrustAllCerts
$trustAllCertsPolicy=New-Object TrustAllCertsPolicy
[System.Net.ServicePointManager]::CertificatePolicy = $trustAllCertsPolicy
[System.Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Use PowerShell to Get GeoLocation of a Computer’s Public IP

Method 1: Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content) Method 2: function getIPGeolocation($ipAddress) {$request = Invoke-RestMethod -Method…

PowerShell: Set User Option Change Password At Next Logon

$ou="OU=Users,DC=corp,DC=hooli,DC=com" $usersInOu=Get-ADUser -Filter * -SearchBase $ou $usersInOu|Set-ADUser -CannotChangePassword:$false -ChangePasswordAtLogon:$false

PowerShell: Increase CPU Count or Memory of VMs via Virtual Machine Manager

# IncreaseCpuandRamViaVMM.ps1 # User Input Variables $vmNames=@( 'TESTWINDOWS', 'TESTWINDOWS2' ) $vmmServer=$env:computername $setCpuCount=8 $setDynamicMemory=$false $dynamicMemoryMinimumGB='2GB' $dynamicMemoryMaximumGB='16GB'…