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

Indications that Chocolatey is locked down

# System's version is less than vendor's current (Chocolatey v0.10.15) 0+000+00[LAX-WEB005]: PS C:\Users\testadmin\Documents> choco source…

Basic HTML and HTML5: Turn an Image into a Link

<h2>CatPhotoApp</h2><main><p>Click here to view more <a href="#">cat photos</a>.</p><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on…

PowerShell: Rebooting a List of Computers

Recommended Method to Process a List of Computers: $computernames='web01','web02','web03' restart-computer -computername $computernames -force -wait Get-WmiObject…