19 December 2021

Select-Object splatting

 $PropSplat = @(
    'Name'
    'Status'

    @{
        Name = 'BoolStatus'
        Expression = {
            if($PSItem.Status -eq 'Running'){$false}else{$true}
        }
    }
)

Get-Service m* | Select-Object $PropSplat

17 December 2021

Return line from CSV file (data)

 in order to find and return a specific line from a csv file (data)


$Recepies = Iomport-CSV C:\temp\recepies.scv

$Recepies.Where({$PSItem.Ingredient_1 -eq 'potato'})

30 November 2021

nslookup with arguments

 in order to use nslookup with arguments


nslookup -type=NS microsoft.com

nslookup -type=NS microsoft.com ns1-205.azure-dns.com



24 February 2021

Search and install packages from powershellgallery

use this command to modify TLS settings if you get an error running the below commands
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

search for all available package providers
Find-PackageProvider

search for a specific package provider
Find-PackageProvider -name nuget

install a package provider
Install-PackageProvider -Name nuget


after you have a package provider setup you can search for packages

search for a specific package. it supports wildcard in name
Find-Package -Name *AzureAD*

install package
Install-Package -Name AzureAD


Change domain for microsoft 365 / azure users from powershell

modify TLS settings if you get errors running commands below
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12


Install-Module -Name MSOnline
(from https://www.powershellgallery.com )

 

Connect-MsolService

$AllMsolUsers = Get-MsolUser -All
$AllToModify = $AllMsolUsers | Where-Object -FilterScript { ($PSItem.Licenses.AccountSkuId -eq 'o365:STANDARDPACK') -and ($PSItem.UserType -eq 'Member') -and $PSItem.IsLicensed}

foreach($User in $AllToModify){

    if($User.UserPrincipalName.Contains('@o365.onmicrosoft.com')){

        $NewPrincipal = $User.UserPrincipalName.Replace('@o365.onmicrosoft.com','@domain.com')

        Set-MsolUserPrincipalName -NewUserPrincipalName $NewPrincipal -UserPrincipalName $User.UserPrincipalName

    }

}


23 February 2021

21 February 2021

Create hashtable from PSObject

$GroupDataObjectHash = [ordered]@{}

$GroupDataObject.PSObject.Properties.Name | %{$GroupDataObjectHash.Add($PSItem, $GroupDataObject.$PSItem)}