SHD Array To Line Of Text

SHD Array To Line Of Text

Often times I need to put an array into a line of text. It can take a while. So I made a powershell to help me make powershells. This little guy takes a single array and turns it into a line of text that I can use in a parameter (“A”,”B”,”C”).

The Break Down

The first part of the code is the parameter block that Grabs the array. This is a simple input. We make sure the array is mandatory.

    param (
        [parameter(HelpMessage = "Input of Array", Mandatory = $true)][array]$TheArray
    )

Next we create a blank line of text that we will be adding everything else to.

$Line = ""

I’m a little anal when it comes down to my outputs. I like everything to be sorted. Its just cleaner and easier for me to understand after the fact. So I sort the Inputs and put the input back into the inputs.

$TheArray = $TheArray | Sort-Object

Now we create the meat and potato of the script. The for loop. We will do a foreach loop in this case. Makes things easier to work with. We put each object into the $Line string with a +=.

foreach ($Info in $TheArray) {
    $Line += """$Info"","
}

Lets take a look at the three ” in front of the $Info variable. “””$Info””,” Inorder to have a qoute, you must have a qoute around it inside a string. “$Info” will just put the value info into the string. But placing a “” adds “$info as part of the string. Doing the same with the end ” does the same. Then adding the , helps build the string.

After the loop is finished, we are left with a odd , mark. The best way to handle that is to remove it. I do this by pushing the value line into it self while removing the last character with substring.

$Line = $Line.Substring(0, $Line.Length - 1)

Here the substring starts at character 0, and counts to the last character of the value line – 1. Basically, we don’t need that last one. So, everything else is pushed back into $Line.

Next we add the lazy man touch and push the string of text into the clip board to be used else where. Life is good. We do this by using the command clip

$Line | Clip

Finally, we display the information to the screen with a write-host command letting the end user know it’s inside their clipboard.

Write-Host "Input is on in your clipboard: $Line"

It’s a simple little script that has saved me on hours worth of work. I use this little guy to create a “Create PDQ deployment script” script. A powershell script that builds powershell scripts.

The Script

I would be amissed if I didn’t post the script, so here you go.

Function Convert-SHDArraytoLineofText {
    [cmdletbinding()]
    param (
        [parameter(HelpMessage = "Input of Array", Mandatory = $true)][array]$TheArray
    )
    $Line = ""
    $TheArray = $TheArray | Sort-Object
    foreach ($Info in $TheArray) {
        $Line += """$Info"","
    }
    $Line = $Line.Substring(0, $Line.Length - 1)
    $Line | Clip
    Write-Host "Input is on in your clipboard: $Line"
}

Roadmap

Like all things, this can be improved upon as well. Here are some ideas and possible future growth.

  • Validation that the input object is an array
  • validation that the input is a single object array instead of a multi object array.
  • A way to handle multiple layers of an array.

Thank you for reading, if you have any questions, feel free to contact me.

PDQ Auto Deploy

PDQ Auto Deploy

We use PDQ where I work, and I am lazy. So, I have made a way to set up devices into Different OUs. This way when I am gone, it’s as easy as putting a computer into an OU and walks away. When I image, The image will load the OS and put the computer into the OU for me, which makes it even sweeter. Then PDQ will hit that OU, check the file, and bam, off to the races with the most up to date software. Makes a great hybrid solution.

Here are a few things you will need before we get started.

  • A Licensed version of PDQ.
  • A laptop Deployment Package
  • A general knowledge of how the conditions work in package deployments.

We first make a new package deployment. This package deployment will have the Laptop package deployment nested inside of it. We will place a special condition on this deployment package. On your new package deployment, select properties and then conditions. Under File we will select “Does Not Exist” and put a directory of your choice and a filename of your choice.

Initial Install – Laptop Base

Your first step is the laptop base install. I name my deployments with a CTP if it is complete. The second step is the “Done” step which creates the condition file. This way it will not redeploy, but you can force it by deleting the file.

Now you have the initial install package built, it’s time to build the scheduling.

  • Right click on the deployment package
  • Select New Schedule
  • Under Targets tab, click choose targets
  • Select Active Directory
  • Select Containers
  • Select the OU you want.
  • Under Triggers select the Interval button
    • Here you change the Time ranges. we do an hour as it takes 30 minutes for the laptop deployment to go through.
  • Select the Package tab
  • Confirm your package is located there.
  • Under Options
    • Here you can tell it to stop redeploying if the deployment was successful. We don’t want to do that because we have a condition and we don’t want it to stay in that OU. This is a good way to create a reminder for yourself by having the Notification send you emails.
  • You’re done.

A quick way to add a computer to the OU while setting it up is the Add-Computer Command.

Add-Computer -DomainName <Your Domain> -OUPath <OU Path for the Initial Install> -NewName <New Computer Name> -Credential (Get-Credential) -restart 

This command will add the computer to the OU that you want and restart it. Make sure you have a group policy set to the OU to turn off or Open the ports on the firewall.

Thank you for reading.