This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//authored by Steven Giesel https://steven-giesel.com/blogPost/d38e70b4-6f36-41ff-8011-b0b0d1f54f6e | |
//usage: await GetResultAsync().OnFailure(ex => Console.WriteLine(ex.Message)); | |
public static async Task OnFailure(this Task task, Action<Exception> onFailure) | |
{ | |
try | |
{ | |
await task.ConfigureAwait(false); | |
} | |
catch (Exception ex) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is authored by Steven Giesel https://steven-giesel.com/blogPost/d38e70b4-6f36-41ff-8011-b0b0d1f54f6e | |
//usage: SendEmailAsync().FireAndForget(errorHandler => Console.WriteLine(errorHandler.Message)); | |
public static void FireAndForget( | |
this Task task, | |
Action<Exception> errorHandler = null) | |
{ | |
task.ContinueWith(t => | |
{ | |
if (t.IsFaulted && errorHandler != null) | |
errorHandler(t.Exception); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Skip = New-PSSessionOption -SkipCACheck -SkipCNCheck | |
Enter-PSSession -ComputerName "IPOFVM" -port "5986" -Credential (Get-Credential) -useSSL -SessionOption $Skip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Invoke-AzVMRunCommand -ResourceGroupName 'resourcegroupname -Name 'nameofthevm' -CommandId 'RunPowerShellScript' -ScriptString 'Enable-PSRemoting -Force | |
New-NetFirewallRule -Name "Allow WinRM HTTPS" -DisplayName "WinRM HTTPS" -Enabled True -Profile Any -Action Allow -Direction Inbound -LocalPort 5986 -Protocol TCP | |
$thumbprint = (New-SelfSignedCertificate -DnsName $env:COMPUTERNAME -CertStoreLocation Cert:\LocalMachine\My).Thumbprint | |
$command = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname=""$env:computername""; CertificateThumbprint=""$thumbprint""}" | |
cmd.exe /C $command' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enable-PSRemoting -Force | |
New-NetFirewallRule -Name "Allow WinRM HTTPS" -DisplayName "WinRM HTTPS" -Enabled True -Profile Any -Action Allow -Direction Inbound -LocalPort 5986 -Protocol TCP | |
$thumbprint = (New-SelfSignedCertificate -DnsName $env:COMPUTERNAME -CertStoreLocation Cert:\LocalMachine\My).Thumbprint | |
$command = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname=""$env:computername""; CertificateThumbprint=""$thumbprint""}" | |
cmd.exe /C $command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$networkSecurityGroup=Get-AzNetworkSecurityGroup | Where-Object -Property Id -EQ $nic.NetworkSecurityGroup[0].Id | |
## Create the security rule. ## | |
Add-AzNetworkSecurityRuleConfig -Name WinRM -NetworkSecurityGroup $networkSecurityGroup ` | |
-Description "Allow WinRM" -Access Allow -Protocol Tcp -Direction Inbound -Priority 300 ` | |
-SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 5986 | |
## Updates the network security group. ## | |
Set-AzNetworkSecurityGroup -NetworkSecurityGroup $networkSecurityGroup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$vmName = "vm-pwsh-remote" | |
$rgName = "CSARG" | |
$vm = Get-AzVM -VMName $vmName -ResourceGroupName $rgName | |
$nic = Get-AzNetworkInterface -ResourceId $vm.NetworkProfile.NetworkInterfaces[0].Id | |
Get-AzNetworkSecurityGroup | Where-Object -Property Id -EQ $nic.NetworkSecurityGroup[0].Id | format-table Name, Location, ResourceGroupName, ProvisioningState, ResourceGuid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function GoAdminFunc(){ | |
If (!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) | |
{ | |
Start-Process -Verb RunAs wt.exe '-p "PowerShell"' | |
Exit | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(HelpMessage = "File with env variables", Mandatory = $true)] | |
[string] | |
$EnvFile | |
) | |
if (!(Test-Path $EnvFile -PathType Leaf)) { | |
Write-Error "$EnvFile is not a file." | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PageCounter=10 | |
FilePath=c:\Work |