Copy Your Profile from ISE to Visual Studio Code
# Get the path to the Profile files $ISEProfile = Join-Path (Split-Path $profile) "Microsoft.PowerShellISE_profile.ps1" $VSCProfile = Join-Path (Split-Path $profile) "Microsoft.VSCode_profile.ps1" # If the ISE Profile exists write the content to the VSCode Profile if(Test-Path $ISEProfile){ # Check if profile exists, create if it does not if(!(Test-Path $VSCProfile)){ New-Item $VSCProfile -ItemType file -Force } # write content to VSCode Profile "`n#...
Get Processor Utilization Percentage
Get-WmiObject win32_processor -ComputerName $computer | Measure-Object -property LoadPercentage -Average | Select @{Label = "Computer"; Expression = {$computer}},@{Label = "CpuUsage"; Expression = {$_.Average}}
Get Memory Utilization Percentage
Get-WmiObject Win32_OperatingSystem -ComputerName $computer | Select @{Label = "Computer"; Expression = {$computer}}, @{Label = "MemoryUsage"; Expression = {100 - [math]::Round(($_.FreePhysicalMemory/$_.TotalVisibleMemorySize)*100,0)}}
Check Remote Desktop Protocol Port
Test-NetConnection -Computer $Server -CommonTCPPort RDP
Get AD Users by Last Password Change Date
Get-ADUser -Filter * -SearchBase "CN=Users,DC=contoso,DC=com" -ResultPageSize 0 -Property CN, pwdLastSet | Select-Object -Property CN, SamAccountName, @{ n = "PwdLastSetDate"; e = { [datetime]::FromFileTime( $_.pwdLastSet ) } } | Sort-Object -Property PwdLastSetDate
Convert From WMI Datetime
[Management.ManagementDateTimeConverter]::ToDateTime($WMIDate)
Check sAMAccountName Requirements
Function Check-sAMAccountName { [CmdletBinding()] [OutputType([string])] param( [parameter(Mandatory=$true)] [string]$ScriptParameters ) # exclude the characters " * + , / : ; < = > ? @ [ \ ] | $excludedChars = 34,42,43,44,47,58,59,60,61,62,63,64,91,92,93,124 $StringBuilder = New-Object System.Text.StringBuilder # split name into Char Array and check each character $sAMAccountName.ToCharArray() | ForEach-Object{ try{ # convert char to ascii decimal $ascii = [byte][char]$_ #...
Format Data Returned from Get-PnPListItem
If you have ever used the SharePoint PnP PowerShell Cmdlets you know that the data returned from the list is not done in the cleanest manor. It is returned as a hashtable and it includes all the internal columns. So, I created a function that will convert this hashtable to a standard PowerShell object and only return the columns you...
Get AD Users by Last Logon Date
Get-ADUser -Filter * -SearchBase "CN=Users,DC=contoso,DC=com" -ResultPageSize 0 -Property CN, LastLogonTimestamp | Select-Object -Property CN, SamAccountName, @{ n = "LastLogonDate"; e = { [datetime]::FromFileTime( $_.lastLogonTimestamp ) } } | Sort-Object -Property LastLogonDate
