Skip to content

Instantly share code, notes, and snippets.

@moiaune
moiaune / CLI.class.php
Created December 2, 2013 13:17
Simple IO class for php CLI.
/*
* Description: Simple IO class for php CLI
* Author: Mads Aune
*/
if(!defined("STDIN")) { define('STDIN', fopen('php://stdin', 'r')); }
class CLI {
public static function getLine($prompt = '') {
echo $prompt . "> ";
@moiaune
moiaune / SlowView.ps1
Created September 1, 2016 11:37
Slow down Powershell output
Function SlowView {
process { $_; Start-Sleep -Milliseconds 500 }
}
@moiaune
moiaune / MicrosoftGraphAuth.ps1
Last active December 18, 2019 12:29
Basic Microsoft Graph Authentication in Powershell
[CmdletBinding()]
param (
[Parameter(Mandatory=$True)]
[string]
$TenantName,
[Parameter(Mandatory=$True)]
[string]
$AppId,
@moiaune
moiaune / Get-LinesOfCode.ps1
Last active May 20, 2021 13:34
Get-LinesOfCode
# Get lines of code in a powershell project
# Inspiration: https://www.limilabs.com/blog/source-lines-of-code-count-using-powershell
function Get-LinesOfCode {
[CmdletBinding()]
param (
[Parameter()]
[string]
$Path = "."
)
@moiaune
moiaune / Find-TerraformAzureResources.ps1
Last active June 3, 2021 09:11
List azurerm/azuread resources in Terraform project
(Get-ChildItem -File -Recurse | Get-Content | Select-String -Pattern 'resource "(azurerm_.+|azuread_.+)" ".*"' -AllMatches).Matches |
ForEach-Object { $_.Groups[1].Value } |
Sort-Object -Unique
function Get-MIDServerDownloadUrl {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string[]]
$InstanceName,
[Parameter()]
[ValidateSet("windows", "linux")]
[string]
PS> Select-MgProfile -Name beta
PS> Get-MgPolicyAuthorizationPolicy | gm | Where-Object { $_.Name -eq "PermissionGrantPolicyIdsAssignedToDefaultUserRole" }
TypeName: Microsoft.Graph.PowerShell.Models.MicrosoftGraphAuthorizationPolicy1
Name MemberType Definition
---- ---------- ----------
PermissionGrantPolicyIdsAssignedToDefaultUserRole Property string[] PermissionGrantPol…
# we need to get the full help document to see the OUTPUT section
PS> Get-Help Get-MgUser -Full
...
INPUTS
Microsoft.Graph.PowerShell.Models.IUsersIdentity
OUTPUTS
Microsoft.Graph.PowerShell.Models.IMicrosoftGraphUser
...
PS> [Microsoft.Graph.PowerShell.Models.IMicrosoftGraphUser].GetProperties()
...
MemberType : Property
Name : UserType
DeclaringType : Microsoft.Graph.PowerShell.Models.IMicrosoftGraphUser
ReflectedType : Microsoft.Graph.PowerShell.Models.IMicrosoftGraphUser
MetadataToken : 385892877
Module : Microsoft.Graph.Users.private.dll
IsCollectible : False
PropertyType : System.String
# GET https://graph.microsoft.com/beta/users
Get-MgUser
# GET https://graph.microsoft.com/beta/users/<id>/authentication/methods
Get-MgUserAuthenticationMethod
# GET https://graph.microsoft.com/beta/roleManagement/directory/roleDefinitions/<id>
Get-MgRoleManagementDirectoryRoleDefinition