Skip to content

Instantly share code, notes, and snippets.

View markroloff's full-sized avatar

Mark Roloff markroloff

  • Denver
View GitHub Profile
@markroloff
markroloff / getAppServiceKeyVaultReferences.ps1
Created October 4, 2022 22:27
Quick PS to fetch connection string details for all app services and map those configs to their respective Key Vault references
$TenantId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # Replace with your tenant ID
# If you don't need to specify a tenant ID, replace with the next comment
# $Subs = Get-AzSubscription
$Subs = Get-AzSubscription -TenantId $TenantId
$results = foreach ($Sub in $Subs) {
Set-AzContext -SubscriptionId $Sub.Id | Out-Null
Write-Host -Message "====== Switching to subscription: $($Sub.Name)"
Write-Host -Message "====== Subscription ID: $($Sub.Id)"
$Result = foreach ($User in $Users) {
# Logic for checking users here, blah, blah...
# We want a [pscustomobject] for each successful check.
# Notice how we just throw the object out there... This is sending output to the success stream (Get-Help about_Output_Streams).
# It'll get picked up by $Result once the loop finishes iterating.
[pscustomobject]@{
Prop1 = $User.Prop1
Prop2 = $User.Prop2
@markroloff
markroloff / checkingUsers.ps1
Created October 14, 2020 13:41
2020-10-14 FB RBooth
$numbers = foreach ($i in 1..10) {"{0:d2}" -f $i}
foreach ($num in $numbers) {
$UserToCheck = "{0}{1}" -f $UserFromSql, $num
Get-ADUser -Identity $UserToCheck
}
$thisIsAString += "one"
$thisIsAString += "two"
$thisIsAString += "three"
$thisIsAString
# onetwothree
$thisIsAString.gettype()
# IsPublic IsSerial Name BaseType
# -------- -------- ---- --------
@markroloff
markroloff / csv.ps1
Created April 29, 2020 05:26
Add column to CSV
$csv = @'
Column1,Column2,Column3
Name1,Mailbox1,Value1
Name2,Mailbox2,Value2
Name3,Mailbox3,Value3
'@ | ConvertFrom-Csv
$Count = 1
foreach ($row in $csv) {
[array]$MachineArray = foreach ($Machine in $Group.Value.migratename) {
"/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Migrate/projects/{2}/machines/{3}?api-version=2018-02-02" -f $SubscriptionId, $RgName, $ProjectName, $Machine
}
$Body = @{
properties = @{
machines = $MachineArray
}
}
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[ValidateScript({
if (-not (Test-Path $_)) {
throw "File or folder does not exist"
}
$true
})]
[System.IO.FileInfo]
@markroloff
markroloff / FormattedCounter.Format.ps1xml
Last active February 17, 2019 19:27
Iron Scripter Prelude #1, advanced solution
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<SelectionSets>
<SelectionSet>
<Name>FormattedCounter</Name>
<Types>
<TypeName>IronScripter.FormattedCounter</TypeName>
</Types>
</SelectionSet>
</SelectionSets>
@markroloff
markroloff / IronScripterPrelude_Simple.ps1
Created February 13, 2019 04:18
Iron Scripter Prelude #1, simple solution
function Get-FormattedCounter {
[CmdletBinding()]
param (
[Parameter(Mandatory,
ValueFromPipeline)]
[Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet[]]
$Counter
)
process {
Function Recover-LogSpace
{
[CmdletBinding()]
Param(
[parameter(ParameterSetName='Multiple')]
[parameter(ValueFromPipelineByPropertyName=$true,
ParameterSetName='Single')]
[string[]]$SqlServer,
[parameter(ValueFromPipelineByPropertyName=$true,