Category: PowerShell

  • How to tell if your PowerShell session is remote

    I wanted to write a conditional to prevent certain things from runing if in a remote PSSession. If you are in a standard PowerShell session the following is returned: [Environment]::GetCommandLineArgs()[0] = C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe If you are in a remote PSSession: [Environment]::GetCommandLineArgs()[0] = C:\Windows\system32\wsmprovhost.exe

  • How to tell if your PowerShell function was called by name or by alias

    I been wanting to write functions that act differently depending on how they were called. I am not sure if this is good practice or not, but I like the idea. Turns out all you need is “$MyInvocation.InvocationName” Look at they following code: If you call the function by alias you get : This function…

  • PowerShell script to force download and install WindowsUpdates

    I have been using the UpdateHF.vbs vbscript for years to patch all my servers. I wrote a simple HTA to wrap it, and it gets executed by psexec. I wanted to take that script, strip it down, and convert it to PowerShell. My intension was to  run it through a PSSession but I get access…

  • PowerShell script to “process” scripts/functions

    I was not happy with the code I wrote in this post. The goal was to write my functions with a “generic” naming convention, and then “process them” – change the naming convention to match my employer’s company name. For example JBMURPHY-AD-GetCurrentSite would be “processed” to Company-AD-GetCurrentSite. In the previous post, I just looped thought…

  • PowerShell script to make a WinPE USB drive

    I wanted to take my previous set of scripts to create a WinPE environment  a step further. I wanted a script to create a bootable WinPE USB drive (UFD). Here is that script (again it is numbered to indicate the order in which to run things). I borrowed the diskpart stuff from here:

  • PowerShell to create Aliases for all your functions

    I have a naming convention for all the function that I write, for example: JBMURPHY-AD-GetGroup. I wanted to create aliases for all my functions with my employers’s name, for example CompanyName-AD-GetGroup. I created the following function to “grep” all the function names and create an “Alias” file. This file would have all the set-alias commands that…

  • PowerShell, Active Setup and running a SCCM package “before log on”

    I have been struggling with the following idea for a while: How to run a package before before a person logs on using SCCM. There is a setting in SCCM that runs when no one is logged on, but if a person reboots and logs on before SCCM fires, the package will never run. Basically…

  • PowerShell Query to find a users computer name in SCCM

    We rely on Remote Assistance. Usually, I just type “msra /offerra” in to my PowerShell session and lookup a the user’s computer name in the SCCM report named “Computers for a specific user name”. I wanted to make that process quicker. I wrote the following script to query SCCM for the “list of computer’s who’s…

  • PowerShell scripts to create a WinPE 4.0 wim/ISO

    I have been  a WinPE hacker since it was only available to SA subscribers. With Vista it was free to the world, and I started moving all my setup processes to it. I have always used the dos batch scripts found in this forum to create a new WinPE ISO. Since WinPE 4.0 is coming out…

  • Specifying Firefox setting (like proxy) on a machine across the enterprise.

    We are interested in how to “push” proxy settings for Firefox across the environment. There are custom builds that claim to work with Group policy, but I wanted to manage the standard Firefox. A little digging shows that you need to create 2 files. First, a file named mozilla.cfg and place it in “C:\Program Files\Mozilla Firefox”.…