Sign in to join the PowerShell Group

  • Hello Surender Kumar.
    I was wonder if you can give me an advise or point to the correct search material.
    I can not seem to be able to figure out how to get TMP to trigger Pin request on boot.

    All machines in our company are part of AD.
    I use NinjaRMM to execute power shell scripts remotely.
    Checkpoint Endpoint Security to trigger BitLocker encryption process on deployment.

    Unfortunately, I was recently tasked with helping my boss to let go of one of our employees next week.
    The issue I got stuck with is he is a developer and remote. The only way I found that I can/should lock him out of the machine is by sending PowerShell script to enable Pin request on boot. Then just restart the machine.
    I am not that good with PowerShell and BitLocker TPM process.
    I can not seem to figure out how to trigger it.

    Setting the Pin by open

    Any help would be greatly appreciated.
    Thank you.

  • To be honest, I don’t remember when I was doing this at all lol.

    I will have to go revisit that as soon as I can. 🙂

    David F.

  • Hi David! Do you have .NET SDK installed? If not, that might be your problem. .NET SDK has a “pack” command which PowerShellGet uses to create packages.

  • The code i wrote is a function which means you have to load it into memory first or add it to your profile so it is autoloaded when you start your powershell prompt.

    to load the function:

    [powershell]. (path to file)backup-grouppolicy.ps1 [/powershell]
    Notice the extra dot in the front of the line. You can also lookup dot-sourcing for a full explainer.

    then the cmdlet Backup-GroupPolicy will be avilable to use like any other cmdlet.

  • I am trying to use this script, but it’s just doing “nothing” when I run it.

    PS C:Scripts> .Backup-GroupPolicy -Path “C:ScriptsGPO_BUs” -Server DC
    PS C:Scripts>

    Any insight on this?

  • But there’s a huge difference between professional programmers and scripting admins. Script writers aren’t always looking at idempotency. And as one of the scripting admins.. if I’m doing something that starts deleting things, I do put in lots of checks, and force error checking.

    But, bad script design is bad script design 🙂

    David F.

  • Good article, nicely written. Another similarity is that from azure portal, one can launch a cloud shell in either of these two environments.

  • There is a reason that proper programming languages do not have the concept of non-terminating errors: it leads to unforeseeable results too often. Because errors tend to occur where nobody is expecting them.

    During 20 years of development and administration, I have met only about a handful of edge-cases where I actually used an empty catch-block (and commented the reason).
    But I have seen a gazillion scripts ignoring errors and causing real damage afterwards. E.g. one of those scripts had the task of cleaning up a directory. The dev ignored errors, since the script could encounter files in use and should just leave them. But one time it failed in determining the path itself and continued with $null as a value. The developer did not expect issues there. But now, his script deleted everything in the default-path, which was the user’s home-folder.

    A very good practice in software development (aside from gaming) is to fail as early as possible. This applies to script development as well.

    And if a developer does really have one of the edge-cases at his hands, where he wants to continue, he can always decide to do so by using an empty catch-block. But this should only be done after careful consideration and not as default-behaviour.

    Ignoring errors by default was just a stupid decision by MS.

  • I would respectively disagree – it’s always a matter of perspective and usage. Depending on the script, setting ErrorActionPreference to Stop can absolutely cause all kinds of noise, bloated problems.

    However, for troubleshooting purposes, sometimes it does help to set EA to Stop.. it’s very circumstantial.

    David F.

  • In your work in Microsoft Azure, should you focus your energies on Azure PowerShell, Azure CLI, or both? This lesson presents a comprehensive comparison of the two primary scripting languages in the Azure cloud.

  • That is really great stuff! I’ve always missed $string.right(n) $string.left(n) -This just about makes up for it

  • Most programming languages provide string functions that can be used to selectively truncate leading or trailing characters. String objects in PowerShell have three such trim() methods that remove not only spaces but also any characters at the beginning and end.

  • You should always set the $ErrorActionPreference to “Stop”.

    The distinction between non-terminating and terminating errors is the source of very many errors on itself. Because in almost all cases, the script is in an unexpected state after an error: the developer just does not remember to check for all possible errors. And letting software run in a state that the developer did not expect is always a bad idea.

    I have seen this happen very often: some batch encounters an error and just keeps doing “something”. The work to clean up this mess is almost always much worse than having a clear error in the first place.

  • Very handy to have – they are increasing the amount of required reporting at work, so this could be a real time-saver. Thanks! –S.

  • Hi

    Can anyone provide me with a script to move my files from my NAS File Server Storage Location directly to my External USB connected drive without interference.

    Regards
    Mario

  • Yeah bad comparison. The only parallel is that both sites are getting somewhat emotional when the topic comes up. I guess with VR / 3D GUIs and AI that writes code we will soon get into the next round.

  • If you were in Australia it would be the opposite. Being a royalist is seriously on the nose. In fact I think GUI’s are far more palatable than royalists.

  • You can learn how to import and export from and to Excel with PowerShell here.

  • Hi 🙂

    I’m pretty new to using PowerShell with Excel, so i was trying to save the results. Probably really easy but I couldn’t find the answer online.

    Import-Excel C:UsersadminDesktoptest123.xlsx -WorksheetName Blad1 -ImportColumns @(1, 2, 4, 5) -startrow 1 -endrow 7
    
    Export-Excel C:tempoutput.txt
  • Load More
© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account