Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin Schvartzman martin77s

View GitHub Profile
@martin77s
martin77s / Send-RemoteToastNotification.ps1
Created Jun 15, 2019
Send toast notification to a remote computer
View Send-RemoteToastNotification.ps1
PARAM(
$RemoteComputer = $env:COMPUTERNAME,
$Sender,
$Message = (Get-Date),
$ImageFile
)
function New-ToastNotification {
param($Sender, $Message, $ImageBase64)
@martin77s
martin77s / Get-AzVmSizesByLocation.ps1
Last active Apr 8, 2019
Get the VM sizes available by location (region)
View Get-AzVmSizesByLocation.ps1
function Get-AzVmSizesByLocation {
[CmdletBinding()]
param($LocationFilter = '*')
Write-Verbose -Message 'Getting all locations with the vmSizes providers'
$locations = Get-AzResourceProvider |
Where-Object { $_.ResourceTypes.ResourceTypeName -contains 'locations/vmSizes' } |
Select-Object -ExpandProperty Locations
View Add-ExtendedAttribute.ps1
function Add-ExtendedAttribute {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[Alias(FullName, PSPath)]
[string[]]$Path,
@martin77s
martin77s / Remove-AzureRMHybridConnection.ps1
Last active Aug 28, 2018
Select and remove Azure Hybrid Connection objects from all namespaces in all resource groups
View Remove-AzureRMHybridConnection.ps1
# Login to Azure
Login-AzureRmAccount
# Select a specific subscription for the context
Get-AzureRmSubscription | Out-GridView -PassThru -Title 'Select Subscription' | Select-AzureRmSubscription
# Get all the Hybrid Connections from all namespaces in all resource groups
$hybridConnections = Get-AzureRmResource -ResourceType Microsoft.Relay/namespaces | ForEach-Object {
$resourceGroupName = $_.ResourceGroupName
Get-AzureRmRelayHybridConnection -ResourceGroupName $resourceGroupName -Namespace $namespace.Name | ForEach-Object {
@martin77s
martin77s / Get-InstalledSoftware.ps1
Created May 26, 2018
Get installed software from the local or remote machine by remotely querying the registry (NOT using Win32_Product)
View Get-InstalledSoftware.ps1
function Get-InstalledSoftware {
[cmdletbinding()]
param(
[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerName = $env:ComputerName
)
begin {
$UninstallRegKey = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall'
}
@martin77s
martin77s / Get-MsiProductInformation.ps1
Created May 26, 2018
Get the product name, version and Id from an MSI installation package
View Get-MsiProductInformation.ps1
function Get-MsiProductInformation {
param($Path)
$msis = Get-ChildItem -File -Path $Path -Filter '*.msi'
foreach($msi in $msis) {
$WI = New-Object -ComObject WindowsInstaller.Installer
$DB = $WI.GetType().InvokeMember("OpenDatabase","InvokeMethod", $Null, $WI, @($msi.FullName, 0))
$query = 'SELECT * FROM Property'
$View = $DB.GetType().InvokeMember("OpenView","InvokeMethod",$Null,$DB,($query))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
@martin77s
martin77s / Disable-Scripting.FileSystemObject.ps1
Last active Feb 12, 2020
Disabling the Scripting.FileSystemObject ComObject (When you get the 0x8002801c error)
View Disable-Scripting.FileSystemObject.ps1
#region Helper functions
function Set-Ownership {
[CmdletBinding(SupportsShouldProcess = $false)]
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Path,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()] [ValidatePattern('(\w+)\\(\w+)')]
View Get-LogonReport.ps1
function Get-LogonReport {
param($ComputerName = $Env:COMPUTERNAME)
$filterXml = '<QueryList><Query Id="0" Path="Security"><Select Path="Security">*[System[(EventID=4624)]]</Select></Query></QueryList>'
$logonTypes = @{
2 = 'Interactive'
3 = 'Network'
4 = 'Batch'
5 = 'Service'
6 = 'Proxy'
@martin77s
martin77s / AddSessionConfigurationPermissions.ps1
Created Feb 25, 2018
Add permissions to a Session Configuration programmatically
View AddSessionConfigurationPermissions.ps1
# The identity to add permissions for
$Identity = "myDomain\nonAdmins"
# The configuration name to change permissions to (default is 'microsoft.powershell')
$sessionConfigurationName = 'microsoft.powershell'
# Get the current permissions on the default endpoint
$sddl = (Get-PSSessionConfiguration -Name $sessionConfigurationName).SecurityDescriptorSddl
@martin77s
martin77s / DscWithWinRmDisabled.ps1
Last active Aug 17, 2020
Using DSC with the WinRM service disabled
View DscWithWinRmDisabled.ps1
#region ### BUILD THE CONFIGURATION ###
# Declare the configuration:
Configuration TestDscWithoutWinRm {
Import-DscResource –ModuleName PSDesiredStateConfiguration
node localhost {
File akada {
Ensure = 'Present'
Type = 'File'
Contents = 'Martin was here!'