Run PSExec From PowerShell
PowerShell remoting help in a lot of areas, but there are times when you need to use PSExec. For those instances, I’ve created a function that you can use to run a command on a remote machine using PSExec. Function ExecutePsExec($computer, $command){ $ping = Test-Connection $computer -Count 1 -Quiet if($ping){ $StdOutput = (Join-path $env:temp "$($computer).txt") Start-Process -FilePath $psexec -ArgumentList "-s...
Homework – Double Digit Addition without Carrying
My son decided to pretend to be sick from school the other day, so after we finished all the work the teach gave us, I decided to make him some extra work. This code will generate a page with 25 double digit addition problems. They haven’t learn to carry over digits yet, so all sums are less than 10. Maybe...
Encrypt All Azure Automation Variables
$ResourceGroupName = '' $AutomationAccountName = '' # Get all variables $variables = Get-AzureRMAutomationVariable -ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName # parse through each unencrypted variable Foreach($var in $variables | Where-Object{$_.Encrypted -ne $True}){ # remove the unencrypted variable Remove-AzureRMAutomationVariable -ResourceGroupName $var.ResourceGroupName -AutomationAccountName $var.AutomationAccountName -Name $var.Name # recreate the variable, with the same values and encrypt it New-AzureRMAutomationVariable -ResourceGroupName $var.ResourceGroupName -AutomationAccountName $var.AutomationAccountName -Name $var.Name...
Get All Azure Virtual Machine IP Addresses
[System.Collections.Generic.List[PSObject]] $IPAddresses = @() $VMs = Get-AzureRMVM foreach($VM in $VMs){ foreach($interface in $VM.NetworkProfile.NetworkInterfaces){ $resource = Get-AzureRMResource -id $interface.Id $nic = Get-AzureRmNetworkInterface -Name $resource.Name -ResourceGroupName $resource.ResourceGroupName Get-AzureRmNetworkInterfaceIpConfig -NetworkInterface $nic | Select-Object @{l='VM';e={$VM.Name}}, PrivateIpAddress, PrivateIpAllocationMethod | ForEach-Object{ $IPAddresses.Add($_) } } } $IPAddresses
Find and Load the Azure Automation Hybrid Registration Module
$installPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Agent").InstallDirectory $modulePath = Get-ChildItem (Join-Path $installPath "AzureAutomation") -Recurse -Include 'HybridRegistration.psd1' | Select-Object -ExpandProperty FullName Import-Module $modulePath
Quick and Easy Day of the Week Date Picker
$today = [datetime]::Today $dates = @() for($i = $today.AddDays(0).DayOfWeek.value__; $i -ge 0; $i--){ $dates += $today.AddDays(-$i) } $date = $dates | Out-GridView -PassThru
Get All Files with a Certain Extension
# add '-recurse' to include sub folders Get-ChildItem -Path $directory -Filter "*.CSV"
Get All Folders in a Directory
# add '-recurse' to include sub folders Get-ChildItem -Path $directory -Directory
Get All Files in a Directory
# add '-recurse' to include sub folders Get-ChildItem -Path $directory -File