This script will list all enabled AD users, user Name, DN,LastLogonDate, User Description, Group user is member of, as well as Group description and group type

Get-AdGroup -Filter * -Properties *  -PipelineVariable g | 
    Get-AdGroupMember |
    where{$_.ObjectClass -eq 'User'} | 
    Get-AdUser -Properties * | 
    Where{$_.Enabled} |
    select @{n='GroupName';e={$g.Name}}, @{n='GroupDescription';e={$g.Description}}, @{n='GroupType';e={$g.groupcategory}}, Name, DistinguishedName, Description, LastLogonDate | export-csv "C:\1.csv" -NoTypeInformation -Encoding UTF8
    sort GroupName, Name

Extend boot partition as part of Volume group

Initial disk size is 20 GB

Check it with fdisk -l command

Partition size – df -h

I extended disk to 40 GB

If new size is not automatically expanded, scan SCSI devices, first list all SCSI devices

ls /sys/class/scsi_device/
2:0:0:0  3:0:0:0  32:0:0:0

And scan all devices individually

echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan
echo 1 > /sys/class/scsi_device/32\:0\:0\:0/device/rescan

Use cfdisk to extend boot partition,select it, (/dev/sda3 in my case) and select “Resize”

Click enter, new size is shown

Then select “Write”, when prompted, type “Yes”, and then select “Quit” and press Enter

With fdisk -l /dev/sda, make sure partition is extended

Next, let’s run parted and resize a partition

parted
GNU Parted 3.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  2097kB  1049kB                     bios_grub
 2      2097kB  1076MB  1074MB  ext4
 3      1076MB  42.9GB  41.9GB

(parted) resizepart
Partition number? 3
End?  [42.9GB]?
(parted) quit
Information: You may need to update /etc/fstab.

Next, resize the physical volume:

pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized

Now, extend the logical volume:

vextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from <19.00 GiB (4863 extents) to <39.00 GiB (9983 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.

Finally, run resize2fs to apply the changes:

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 5
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 10222592 (4k) blocks long.

Verify changes: df -h, partition is extended from 20 to 40 GB

Extend boot partition as NOT part of Volume group

First, detect root partition with df -h

In this example i expanded disk for 10 GB, so total size is 20+10=30 GB

Run again cfdisk and select boot partition (/dev/sda2 in my case) and select “Resize”

Click Enter,select “Write”, and they type “Yes” and then select “Quit” and press Enter

Make sure disk is extended

Now, we just need to resize filesystem

resize2fs /dev/sda2
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 4
The filesystem on /dev/sda2 is now 7863803 (4k) blocks long.

Now, check partition is extended from 20 to 30 GB

Recently, i had to get a list of computers where specific folder exists, if you need to search all computers just remove filter 'operatingsystem -notlike "server"'.

Script will output machines name where folder/file exists

Try{
    $computers = Get-ADComputer -Filter 'operatingsystem -notlike "*server*" -and enabled -eq "true"' `
    -Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address |
    Select-Object -ExpandProperty Name

    foreach ($Computer in $computers) {
    if(Test-Path "\\$Computer\c$\Program Files (x86)\Microsoft Dynamics AX\50\Client\Bin"){

    Write-Output $Computer
    }
  }
}
Catch{
     Write-Warning $Error[0]
}

This script searches Microsoft Partner Center’s all tenants for specific user. It takes 2 parameters:

$userName – it’s User’s display name in Partner Center

$csvPath – Path for report file

# Bellow 2 commented commands are required only once

# Install-Module -Name PartnerCenter -AllowClobber
# Import-Module PartnerCenter 
# Connect to partner center 
Connect-PartnerCenter

Function Get-User-From-PartnerCenter {
[cmdletbinding()]
Param (
[parameter(Mandatory=$true)]
[string]$csvPath,
[string]$userName
)
# End of Parameters
 Process {
         $Result = ""   
         $Results = @() 
         $ErrorActionPreference = "Stop"

         # Get all tenats in Partner center

         $Customers = Get-PartnerCustomer

         # Search every tenant for specific user

         $Customers.ForEach({

         Try{
                $CustId = $_.CustomerId
                $CustName = $_.Name
                $CustomerUser = Get-PartnerCustomerUser -CustomerId $CustId | Where-Object {
                $_.DisplayName -like "*$userName*"
                } | ForEach-Object { New-Object -TypeName PSCustomObject -Property @{
                Name = $_.DisplayName
                'User Principal Name' = $_.UserPrincipalName
                }
               }
               
               # If user is found, Write it to CSV file

                if($CustomerUser -notlike ''){
                  $Result = @{'Customer Name' = $CustName; 'User Name' = $CustomerUser.Name; 'User Principal Name' = $CustomerUser.'User Principal Name'}
                  $Results += New-Object PSObject -Property $Result
                  $Results = $Results | Select-Object 'Customer Name','User Name','User Principal Name' | Export-Csv -Path $csvPath -Notype -append
                }
         }
            
         Catch{

               Write-Warning "Caught an exception:"
               Write-Warning "Exception Type: $($_.Exception.GetType().FullName)"
               Write-Warning "Exception Message: $($_.Exception.Message) - Tenant:$CustName"
          }
         }
       )
     }
    }

Usage:

Get-User-From-PartnerCenter -csvPath 'C:\Users\user\partnerCenter.csv' -userName "Tony Stark"

Recently, i needed to create list of all Office 365 subscriptions Get-MsolSubscription returns total number of purchased licenses and expiration date and Get-MsolAccountSku returns total and used licenses, but no expiry date, so i had to “join” these 2 command somehow

# declare variables for storing results
$Result=""   
$Results=@() 
#Get available subscriptions in the tenant 
$Subscriptions= Get-MsolSubscription | foreach{
 $SubscriptionName=$_.SKUPartNumber
 $SubscribedOn=$_.DateCreated
 $ExpiryDate=$_.NextLifeCycleDate
 $Status=$_.Status
 $TotalLicenses=$_.TotalLicenses
 # get number of assigned licences
 $consumedLicences = Get-MsolAccountSku | Where-Object {
        $_.SkuPartNumber -like $SubscriptionName
    } | ForEach-Object {
        $_.ConsumedUnits
    }
 # export to CSV
 $Result=@{'Subscription Name'=$SubscriptionName;'Total Licenses'=$TotalLicenses;'Used Licences'=$consumedLicences;'Expiry Date'=$ExpiryDate;'Status'=$Status}
 $Results+= New-Object PSObject -Property $Result
 $Results | Select-Object 'Subscription Name','Total Licenses','Used Licences','License Expiry Date','Status' | Export-Csv -Path $ExportCSV -Notype -Append  
  }

Filter is applied with Where-Object before doing anything else – while each output object from Get-MsolAccountSku still has it’s properties intact. Then we use ForEach-Object to extract the value of ConsumedUnits.

After terraform init, when trying to plan or deploy resources, terraform just hangs. On some Windows 10 machine it works fine, on other not.Terraform version v0.14.4

Debug logs returns following error: waiting for RPC address: path=.terraform/providers/registry.terraform.io/hashicorp/aws/

After some googling, found out that adding following environmental variable fixes the issue:GODEBUG=asyncpreemptoff=1

On windows, it can be added as User or system variable

On linux/MAC:

export GODEBUG=asyncpreemptoff=1

1.csv file:

"name","distinguishedname","LastLogonDate"
"Administrator","CN=Administrator,CN=Users,DC=test,DC=com","02.01.2021. 19:35:55"
"user1","CN=user1,DC=test,DC=com","07.12.2020. 17:06:57"
"user2","CN=user2,DC=test,DC=com","07.12.2020. 17:06:57"

We can extract any column value by creating array and storing column content in it:

$names = @()
$dns = @()
$logonTimes = @()


Import-Csv "C:\Users\user\Downloads\1.csv" -delimiter "," |`

ForEach-Object {
    $names += $_.name
    $dns += $_.distinguishedname
    $logonTimes = $_.LastLogonDate
  }

  Foreach ($name in $names){
      Write-Host $name
}

Get content of first column (name)

Administrator
user1
user2

We can also use different approach,in this example, we’ll get values of LastLogonDate column:

$csv = Import-Csv "C:\Users\user\Downloads\1.csv" -delimiter "," 
foreach ($cs in $csv){
    $lastLogon = $cs.LastLogonDate
    Write-Host $lastLogon
}

Results:

02.01.2021. 19:35:55
07.12.2020. 17:06:57
07.12.2020. 17:06:57

We have Remote Desktop apps hosted on Windows server 2012 R2, for past few years. Everything worked fine for years, then suddenly, we started to get following error:

“Your computer can’t connect to the remote computer because the Remote Desktop Gateway server address is unreachable or incorrect. Type a valid Remote Desktop Gateway server address”

Opened https://remote.example.com/RDWEB, type credentials, remote apps are shown, then after clicking on application, again prompted for password and getting error above.Restarted RDP gateway, recreated Remote session no help. The strange things is that all works fine from the LAN, but not from the internet. Even stranger things is that Remote Application can be launched from mobile phone outside company network.

After some googling, found a “fix”, on machines from which tried to launch Remote App (
Windows 10), added following entry in registry:

reg.exe Add "HKCU\Software\Microsoft\Terminal Server Client" /V "RDGClientTransport" /T REG_DWORD /D "1"

It started to work,but, according to this thread , traffic is sent using HTTP , in other words, in plain text.

So tried to find other solution.

In Remote properties of RDP Gateway, server, unchecked “Allow connections only from computers Running Remote Desktop with Network Layer Authentication (recommended) “

Then, on client machine removed registry “fix” and finally was able to launch remote app from the internet.

Just for curiosity, captured packets between client computer and RDP Gateway with Wireshark, and traffic was encrypted

Input.CSV file was like this:

Entity;Type
user1;Account
;
User2;Account
;
;
user3;Account
;

I wanted to remove all empty/blank lines from csv file

Get-Content "C:\input.csv" | Where { $_.Replace(";","") -ne "" } | Out-File C:\output.csv

output.csv

Entity;Type
user1;Account
User2;Account
user3;Account

Script will check if particular port is opened or not

Function Check-Port{
[cmdletbinding()]
Param (
[parameter(Mandatory=$true)]
[string]$ipaddress,
[string]$port
)
# End of Parameters
Process{
  $Date = Get-Date
  $MyDate =  " " + $Date.Day + "." + $Date.Month + "." + $Date.Year + " " + $date.Hour + ":" + $date.Minute
  
  Try{
     $connection = $null
     $connection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port)
  }

  Catch{
       Write-Warning $Error[0]
     }
  if ($connection.Connected){
     Write-Host "Port $port is open - $MyDate" -ForegroundColor Green
    }
   }
 }

Usage example and output