Skip to content

Instantly share code, notes, and snippets.

View janegilring's full-sized avatar

Jan Egil Ring janegilring

View GitHub Profile
{
"final_space": true,
"console_title": true,
"console_title_style": "folder",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"horizontal_offset": 0,
"vertical_offset": 0,
@janegilring
janegilring / profile.ps1
Last active August 6, 2023 14:23
PowerShell profile used cross-platform (Linux, macOS, Windows)
#Requires -Version 7
# Version 1.3.7
# Cross-platform PowerShell profile based on https://devblogs.microsoft.com/powershell/optimizing-your-profile/
# check if newer version
$gistUrl = 'https://api.github.com/gists/a4e366e6b01f0b70eae90557dfc9d21d'
$latestVersionFile = [System.IO.Path]::Combine("$HOME", '.latest_profile_version')
$versionRegEx = '# Version (?<version>\d+\.\d+\.\d+)'
@janegilring
janegilring / Set-HueLight.ps1
Created April 3, 2020 03:28
Configure color of Philips Hue Lightstrip - example usage: https://twitter.com/JanEgilRing/status/1245433266099965959
function r {
if (-not (Get-Module -Name PoSHue)) {
Import-Module -Name PoSHue
}
$BridgeAPIKey = $env:HueAPIKey
$BridgeIPAddress = '10.0.1.236'
@janegilring
janegilring / PowerBI-DataQuery.ps1
Created February 29, 2020 14:27
An example on how to query data from Power BI using the SQL Server PowerShell module
Install-Module -Name SqlServer -Scope CurrentUser
$cred = Get-Credential
# Executing a DAX-query to retrieve the property we need in a given scenario
Invoke-ASCmd -Credential $cred -Query "EVALUATE(VALUES(Customers[Id]))" -Server "powerbi://api.powerbi.com/v1.0/myorg/ContosoWorkspace" -Database "CustomerData"
# The returned data is an XML-string, so we can cast the data to an XML-typed variable in PowerShell
[xml]$Data = Invoke-ASCmd -Credential $cred -Query "EVALUATE(VALUES(Customers[Id]))" -Server "powerbi://api.powerbi.com/v1.0/myorg/ContosoWorkspace" -Database "CustomerData"
@janegilring
janegilring / PowerBI-Basics.ps1
Created February 29, 2020 14:23
Example on getting started with the Power BI PowerShell module
Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser
$Credential = Get-Credential
Connect-PowerBIServiceAccount -Credential $Credential
$Workspace = Get-PowerBIWorkspace -Name 'HR Data'
Get-PowerBIDataset -Workspace $Workspace | ft name,ConfiguredBy,IsRefreshable
@janegilring
janegilring / AzureFileSyncAgent.ps1
Created August 3, 2019 05:17
Example of using the AzureFileSyncAgent DSC resource
Configuration HybridFileServer
{
param (
$AzureCredential = (Get-Credential)
)
Import-DscResource -ModuleName xPSDesiredStateConfiguration -ModuleVersion 8.4.0.0
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName PackageManagement -ModuleVersion 1.2.4
Import-DscResource -ModuleName AzureFileSyncAgentDsc -ModuleVersion 1.1.5
@janegilring
janegilring / AzureFileSyncServerEndpoint.ps1
Created August 3, 2019 05:13
Example of using the AzureFileSyncServerEndpoint DSC resource
Configuration HybridFileServer
{
param (
$AzureCredential = (Get-Credential)
)
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName AzureFileSyncAgentDsc -ModuleVersion 1.1.5
Node FS01 {
@janegilring
janegilring / Set-NetFirewallExchangeOnlineRule.ps1
Created August 26, 2018 19:17
Shows how to leverage the Get-Office365Endpoint script by Joerg Hochwald to configure Windows Firewall on a Microsoft Exchange Server to restrict SMTP traffic only from IP ranges used by Exchange Online Protection
# Define the Get-Office365Endpoint function in the current PowerShell session
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/janegilring/PSCommunity/master/Office%20365/Get-Office365Endpoint.ps1'))
# Retrieve endpoints for Exchange Online and filter on TCP port 25
$ExchangeOnlineEndpoints = Get-Office365Endpoint -Services Exchange
$ExchangeOnlineSMTPEndpoints = $ExchangeOnlineEndpoints | Where-Object {
$PSItem.ip -and
$PSItem.DisplayName -eq 'Exchange Online' -and
@janegilring
janegilring / gist:f2147a1f48f0e461139808262fbb2a5d
Created July 8, 2018 17:54
Example on how to use a Windows VM Managed Service Identity (MSI) access token to authenticate to Azure AD PowerShell
# Step 1 - Enable MSI on the resource - in this case a virtual machine
# Step 2 - Assign permissions to the MSI - in this example full permissions to Azure AD
$Principal = Get-AzureADServicePrincipal -searchstring MGMT-AZ-01
$Role = Get-AzureADDirectoryRole | Where-Object DisplayName -Like 'Company Administrator'
Add-AzureADDirectoryRoleMember -ObjectId $Role.ObjectId -RefObjectId $Principal.ObjectId
# Step 3 - Get an access token. Note that the resource we are requesting a token for is https://graph.windows.net
$response = Invoke-WebRequest -UseBasicParsing -Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://graph.windows.net/' -Method GET -Headers @{Metadata="true"}
@janegilring
janegilring / Packer-Windows.json
Created April 27, 2018 05:42
Packer file for building Windows base images
{
"builders": [
{
"type": "hyperv-iso",
"output_directory": "./output-{{ user `os_name` }}-base-hyperv/",
"temp_path": "C:\\ClusterStorage\\HYPData01\\PackerTemplates\\temp",
"vm_name": "{{ user `os_name` }}-base",
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "sha1",