Background Let us do a very quick exercise. The exercise will be to validate whether a variable's content is null. Code Script Output Output - Image Output - Text Output - Explanation Type of Test Test Test Result variable -eq $null ($day -eq $null) False $null -eq variable ($null -eq $day) False variable … Continue reading Powershell:- Is String Variable Null?
PowerShell ( Microsoft )
Get Computer Fully Qualified Domain Name ( Using Powershell )
Background Recently I needed to confirm a remote's computer fully qualified domain name. Options GUI Win OS Outline Access Control Panel \ System and Security \ System The computer name will be listed Group Box:- Computer name, domain, and workgroup settings Item:- Full Computer Name Images Image - View basic information about your computer Console … Continue reading Get Computer Fully Qualified Domain Name ( Using Powershell )
Active Directory:- Get Group Members using Powershell ( Get-ADGroupMember )
Background I need to query Active Directory ( AD ) and get a listing of group members matching a specific criteria. GUI Active Directory Users and Computers Active Directory Users and Computers MMC is a very capable tool for querying AD. Console Powershell - Active Directory Get-ADGroupMember Here is how I will do so using … Continue reading Active Directory:- Get Group Members using Powershell ( Get-ADGroupMember )
Powershell:- Repeat Character
Background A few weeks ago, I was in a jam. I wanted to draw a line on my console to separate out two sections of output. It seems terrible inefficient to use Write-Output("----------------------------------------"). I preferred something like Write-Output(repeatChars('-', 80)). Code Here is stolen code that I have to come back and properly attribute ( give … Continue reading Powershell:- Repeat Character
Powershell:- Raising an ArgumentException
Background Good software engineers engage in defensive development. As opposed to offensive practices. Code In this post, we will employ .Net's System.ArgumentException to offer examples of how to better help the developer know why an application is failing. Outline Function:- calculatorGraceful If operation is equal and divisor is 0 If exceptionType is 1 throw (New-Object … Continue reading Powershell:- Raising an ArgumentException
Powershell:- Sourcing Files
Background Microsoft's Powershell is a very matured tool that provides various tooling towards modularized software development. In this post, we will considering one of it foundational offerings. Sourcing For instance, you download a powershell script from an online source. You look at the code and you like the way it does something. So you identify … Continue reading Powershell:- Sourcing Files
Powershell:- Import-CSV – Filtered List
Background Employing Import-CSV to read in a datafile. My use case will work better if I am able to comment out certain entries' as opposed to outright removing them from the datafile. Datafiles Datafile - Number of Lines - 11 Script Outline Read File $listofPersons = @(Import-CSV -Path $filename -Delimiter "|"); Filter List Construct Discard … Continue reading Powershell:- Import-CSV – Filtered List
Powershell:- Function Invocation Pass Variables By Reference
Background Quick Refresher on Powershell. Specifically, how to pass arguments to functions by value and by reference. Outline Global Variables Declare functionName [string] $global:functionName = ""; Prefix variable name with $global Function Get-FunctionName Function stringConcatByValueAndReference Function Declaration stringConcatByValueAndReference([string]$str1, [string]$str2, [ref]$result) Input Variables str1 and str2 passed by value Output Variable result passed by reference Set … Continue reading Powershell:- Function Invocation Pass Variables By Reference
Powershell:- Import-CSV And Array Subexpression
Background Experienced a little error using Import-CSV. Error PropertyNotFoundException Error Image Error Text Datafiles Datafile - Number of Lines - 01 Datafile - Number of Lines - 02 Code Original Revision Use Scenario Original Code File - Number of Lines - 2 Invoke Output Output - Image Output - Text … Continue reading Powershell:- Import-CSV And Array Subexpression
You must be logged in to post a comment.