VCommander.psm1
<#
.SYNOPSIS Helper function to bypass certificate errors .DESCRIPTION Helper function to bypass certificate errors .EXAMPLE Ignore-SslErrors #> function Set-IgnoreSslErrors { # Create a compilation environment $Provider=New-Object Microsoft.CSharp.CSharpCodeProvider $Compiler=$Provider.CreateCompiler() $Params=New-Object System.CodeDom.Compiler.CompilerParameters $Params.GenerateExecutable=$False $Params.GenerateInMemory=$True $Params.IncludeDebugInformation=$False $Params.ReferencedAssemblies.Add("System.DLL") > $null $TASource=@' namespace Local.ToolkitExtensions.Net.CertificatePolicy { public class TrustAll : System.Net.ICertificatePolicy { public TrustAll() { } public bool CheckValidationResult(System.Net.ServicePoint sp, System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest req, int problem) { return true; } } } '@ $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource) $TAAssembly=$TAResults.CompiledAssembly ## We now create an instance of the TrustAll and attach it to the ServicePointManager $TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll") [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll } <# .SYNOPSIS Helper function to convert string to base 64 .DESCRIPTION Helper function to convert string to base 64 .EXAMPLE ConvertTo-Base64 'myString' #> function ConvertTo-Base64($string) { $bytes = [System.Text.Encoding]::UTF8.GetBytes($string); $encoded = [System.Convert]::ToBase64String($bytes); return $encoded; } <# .SYNOPSIS Helper function to convert string from base 64 .DESCRIPTION Helper function to convert string from base 64 .EXAMPLE ConvertFrom-Base64 'myString' #> function ConvertFrom-Base64($string) { $bytes = [System.Convert]::FromBase64String($string); $decoded = [System.Text.Encoding]::UTF8.GetString($bytes); return $decoded; } Export-ModuleMember -function *Set-IgnoreSslErrors* Export-ModuleMember -function *ConvertTo-Base64* Export-ModuleMember -function *ConvertFrom-Base64* |