Tag Archives: powershell

PowerShell: Get-FileEncoding

VertigoRay/ February 4, 2015/ Uncategorized/ 1 comments

I often work in PowerShell, and one day I needed to create a script that would pull the file encoding out a file. Encodings However, this proved to be difficult since most encodings don’t require a BOM (Byte Order Mark). Here’s some good information that I found on the subject: Automatically determining the correct encoding for a given byte array

Read More

PowerShell: Write-Json

VertigoRay/ August 11, 2014/ Uncategorized/ 0 comments

I needed to write a Json object in human readable format. This is my solution to this problem. The `$json` parameter expects a Json object, returned from `ConvertFrom-Json`. https://gist.github.com/VertigoRay/789809a1e74fb9ab2009

PowerShell: Invoke-Command

VertigoRay/ November 29, 2012/ Uncategorized/ 0 comments

Had some issues with Invoke-Command today: [PS] H:>Invoke-Command -ScriptBlock { get-process } -ComputerName MyScriptServer It gave me the following error: Connecting to remote server failed with the following error message : WinRM cannot process the request. The following error occured while using Kerberos authentication: The network path was not found.  Possible causes are:   -The user name or password specified

Read More

PowerShell – Checking if OU exists

VertigoRay/ February 22, 2012/ Uncategorized/ 0 comments

After starting work on a function, I stumbled across the sourced link.  I wanted to expand on that post. That simple method only works well if the LDAP Path is clean.  If you’re possibly working with unclean data (or typo the DC structure), you’ll need to catch your errors. https://gist.github.com/VertigoRay/6091753 Since DC=domain,DC=com doesn’t exist (or at least isn’t accessible for an

Read More

Active Directory – Validate Group SamAccountName

VertigoRay/ February 21, 2012/ Uncategorized/ 0 comments

Did a lot of digging to find the details needed so that I can write a Reg Ex to validate an AD Group SamAccountName.  Here’s what I got and I wanted to share … (^[^. “”/\[]:|\+=;?*][^””/\[]:|\+=;?*]{1,63})(?(1)|[^.]$) This translates to: Not Starting with a period (.) or a space ( ). This, by design, excludes strings consisting solely of all periods (.)

Read More

PowerShell – Random Color

VertigoRay/ February 15, 2012/ Uncategorized/ 0 comments

Just messing around here, but thought others might want to know how to randomly (or intelligently) grab a color.  There’s basically three parts to this process. Get the number of colors. Grab a random color. Apply the color. I’ve done the above three steps in these three lines of code … $max = [System.ConsoleColor].GetFields().Count – 1 $color = [System.ConsoleColor](Get-Random -Min

Read More

PowerShell – Pick a Domain Controller

VertigoRay/ February 2, 2012/ Uncategorized/ 0 comments

I use a global variable to pick a Domain Controller so that I’m not constantly bouncing back and forth between Domain Controllers when running scripts. This helps to mitigate errors due to replication delays (normally, just a few seconds). For Example, when you’re scripting and try to run Set-ADUser command followed immediately by a Get-ADUser command without specifying the -Server

Read More