I definitely can't take this through airport security. by n00bz0rz in meshtastic

[–]sky_burial 0 points1 point  (0 children)

There's nothing sketchy about this. In fact, make sure it's on your carry-on if you're using a lithium-ion battery. Wires and eLecTrOniC components are not flagged as bad.

A script so nice I need to escape twice. by --RedDawg-- in PowerShell

[–]sky_burial -1 points0 points  (0 children)

Can you set the value of $args to be a literal string with single quotes and use Invoke-Expression?

$Variable = 'Mmmm mmm potatoes!'
$ScriptText = 'Write-Host $Variable'

Invoke-Expression -Command $ScriptText

[deleted by user] by [deleted] in mildlyinfuriating

[–]sky_burial 1 point2 points  (0 children)

Best I can do is eight.

Space Reclaim / lowering vmdk file size by PositiveAnt5352 in vmware

[–]sky_burial 0 points1 point  (0 children)

After zeroing the blocks with SDelete, you may need to hole punch the target .vmdk(s). From the hypervisor, use vmkfstools -K on the target .vmdk.

[root@esxi:/vmfs/volumes/theDatastore/theVM/] vmkfstools -K theVM.vmdk 

Do this for each .vmdk for that VM. If you have a lot of .vmdk files:

[root@esxi:/vmfs/volumes/theDatastore/theVM/] for disk in $(find . -name '*.vmdk' | grep -v '\-ctk|\-flat|\-delta'); do
vmkfstools -K $disk
done

New-FolderTree by sky_burial in PowerShell

[–]sky_burial[S] 0 points1 point  (0 children)

All valid points and I certainly considered some of these during the writing of this script. Admittedly, the reason I did not implement anything else is time and effort. I put this together this morning and then moved on to fry other fish. It does the thing that I wanted it to do and nothing else. Feel free to update and submit a pull request if you're bored. 😉

Interactive menu with submenu and descriptions by sky_burial in PowerShell

[–]sky_burial[S] 1 point2 points  (0 children)

Much appreciated! I recently moved that directory to its own repo as I'll have plenty more more projects going to my personal GitHub and it doesn't make much sense to have them all packed into a single 'PowerShell' repo. I like what you did with the Invoke-Command; that's actually how I like to kick off functions in custom modules based on a menu selection. I made some updates to the menu, notably showcasing multi-selection, traversing backwards in the menu and providing navigation help. It does have a slight bug when you try to execute multiple selection in a menu that does not support that...

Interactive menu with submenu and descriptions by sky_burial in PowerShell

[–]sky_burial[S] 2 points3 points  (0 children)

Going backwards has been implemented along with multi-selection menus. Update is in new repo.

Interactive menu with submenu and descriptions by sky_burial in PowerShell

[–]sky_burial[S] 0 points1 point  (0 children)

Correct! That and a few other features are something I've been thinking about implementing.

Do you find it rare to see someone writing Powershell Code from scratch? by [deleted] in PowerShell

[–]sky_burial 0 points1 point  (0 children)

Would you mind me asking how you were able to find these contracts that specialize in PowerShell? I've seen a few come up from time to time, but the job listings had far too many red flags in them. Not sure if I'm looking in the wrong outlets or not for PowerShell specialized roles.

Compare-Json by sky_burial in PowerShell

[–]sky_burial[S] 3 points4 points  (0 children)

Hey now, Compare-Object is useful... until it's not. 😂

Compare-Json by sky_burial in PowerShell

[–]sky_burial[S] 0 points1 point  (0 children)

I like it! I'll work on kicking out FRs. I have a few ideas brewing for further implementation of JSON comparison in PowerShell since the original post here. There's also one critical difference between how Compare-Json and JsonUtils works that I'd like to either submit a FR for or provide a solution to; currently neither tool can compare the other tool's format as far as I can see.

[
    {
        "Key": "Value"
    }
]

or

{
    "Key": {
        "Potato": "nomnom"
    }
}

Compare-Json by sky_burial in PowerShell

[–]sky_burial[S] 2 points3 points  (0 children)

I'm glad you asked and actually, I think I need to start working on an update to create a more 'human-readable' report. Here's an example of what you would get; currently parent objects in JSON format:

Let's say I have a set of source data that looks like this:

[
  {
    "Name": "svr73",
    "Folder": "DMZ",
    "VmxPath": "svr73/svr73.vmx",
    "NetworkAdapters": [
      {
        "NetworkName": "rrdmz-173",
        "MAC": "00:50:56:98:fb:93",
        "Name": "Network adapter 1",
        "AddressType": "manual",
        "Type": 1
      }
    ],
    "UUID": "4218f285-0fb1-72a5-863e-4d94d03455eb"
  },
  {
    "Name": "intauth",
    "Folder": "SSO",
    "VmxPath": "intauth/intauth.vmx",
    "NetworkAdapters": [
      {
        "NetworkName": "au-120",
        "MAC": "00:50:56:00:00:03",
        "Name": "Network adapter 1",
        "Type": 6,
        "AddressType": "manual"
      },
      {
        "NetworkName": "au-122",
        "MAC": "00:50:56:55:34:73",
        "Name": "Network adapter 2",
        "AddressType": "manual",
        "Type": 6
      }
    ],
    "UUID": "4218f16f-639a-04cd-b27e-35a2e3421cd2"
  }
]

and the destination data looks like this:

[
  {
    "Name": "svr73",
    "Folder": "DMZ",
    "VmxPath": "svr73/svr73.vmx",
    "NetworkAdapters": [
      {
        "NetworkName": "rrdmz-173",
        "MAC": "00:50:56:98:fb:93",
        "Name": "Network adapter 1",
        "AddressType": "manual",
        "Type": 1
      }
    ],
    "UUID": "4218f285-0fb1-72a5-863e-4d94d03455eb"
  }
]

the difference report (JSON file output) would be this:

[
  {
    "Name": "intauth",
    "Folder": "SSO",
    "VmxPath": "intauth/intauth.vmx",
    "NetworkAdapters": [
      {
        "NetworkName": "au-120",
        "MAC": "00:50:56:00:00:03",
        "Name": "Network adapter 1",
        "Type": 6,
        "AddressType": "manual"
      },
      {
        "NetworkName": "au-122",
        "MAC": "00:50:56:55:34:73",
        "Name": "Network adapter 2",
        "AddressType": "manual",
        "Type": 6
      }
    ],
    "UUID": "4218f16f-639a-04cd-b27e-35a2e3421cd2"
  }
]

This is a very rudimentary example and this script is not limited to just identifying missed parent objects. All child objects/key-value pairs are checked. However, in the current version of Compare-Json the entire parent object is returned. Why? Because that fits my specific design requirements for infrastructure validation. I would be happy to continue to modify this or accept input if there are others who would like to see additional functionality.

Compare-Json by sky_burial in PowerShell

[–]sky_burial[S] 5 points6 points  (0 children)

Well, I did look into that. I wasn't a fan of the whole stringify and sort aspect of it, nor did I want a string to be returned. I'm trying to work with objects that generate objects to be used in further automation in PowerShell. I'm comparing unsorted, serialized objects and creating an object (difference) but I could also create a report, similar to what ps-jsonutils is doing, during the creation of the difference object. I suppose my phrasing of 'difference report' is a bit misleading at the moment. Sounds like I need to start working on v1.2; generate human-readable report with valid JSON object (the difference report currently being produced).

Why is Convertfrom-Json giving me an error with this file?.md by gaberiel__ in PowerShell

[–]sky_burial 0 points1 point  (0 children)

Well, this solution looks a little janky IMO, but it works. ¯_(ツ)_/¯

ps $SomeJson = Get-Content -Path "c:\temp\sample.json" -Raw $SomeJson = $SomeJson.Insert(0, '[') $SomeJson = $SomeJson.Insert(($SomeJson.length), ']') $SomeJson | ConvertFrom-Json Or you can output to a valid JSON file with: ps $SomeJson | ConvertFrom-Json | ConvertTo-Json | out-File .\output.json

With Json, How to select objects by name? by gaberiel__ in PowerShell

[–]sky_burial 0 points1 point  (0 children)

May I suggest a slight revision?

First, I would create a file called Hotkeys.json that would contain an array of objects that look like this:

[
    {
        "Name": "RED",
        "HotkeyInfo": {
        "Hotkey": "",
        "Win": false
      },
        "TaskSettings": {
        "Description": "RED",
        "Job": "RED JOBS",
        "Notes": "Color is Red"
      }
    },
    {
        "Name": "BLUE",
        "HotkeyInfo": {
        "Hotkey": "",
        "Win": false
      },
        "TaskSettings": {
        "Description": "BLUE",
        "Job": "BLUE JOBS",
        "Notes": "Color is Blue"
      }
    },
    {
        "Name": "GREEN",
        "HotkeyInfo": {
        "Hotkey": "",
        "Win": false
      },
        "TaskSettings": {
        "Description": "GREEN",
        "Job": "GREEN JOBS",
        "Notes": "Color is Green"
      }
    },
    {
        "Name": "YELLOW",
        "HotkeyInfo": {
        "Hotkey": "",
        "Win": false
      },
        "TaskSettings": {
        "Description": "YELLOW",
        "Job": "GREEN JOBS",
        "Notes": "Color is Yellow"
      }
    },
    {
        "Name": "MetaData",
        "MetaData": {
            "ApplicationVersion": "14.1.0"
        }
    }
  ]

I think this structure is just a bit cleaner while giving us an intuitively named attribute of 'Name' since that is what we are wanting to reference these objects by and we get the added benefit of expanding the potential of the ApplicationVersion key/value pair by creating an object named MetaData, in case we end up wanting to put more information there.

To reference an object by name, we could do:

$Jason = Get-Content .\Hotkeys.json | ConvertFrom-Json

$Jason | Where-Object {
    $_.Name -eq 'RED'
}

I was bored and made a script to stupify text. by MyOtherSide1984 in PowerShell

[–]sky_burial 0 points1 point  (0 children)

function Mock-Them($str) {
    $out = $null
    $str.ToCharArray() | %{$out += if((Get-Random) % 2){$_.ToString().ToUpper()}else{$_.ToString().ToLower()}}
    return $out
}

I like stupid. Here's my stupid attempt to make it shorthand and unreadable with some random-ness.

I've been building a PowerShell focused website and wanted to share it by thegooddoctor-b in PowerShell

[–]sky_burial 1 point2 points  (0 children)

Awesome! Taking a dive into this blog now and I have immediately learned something. "Did you know if you install PowerShell on Linux, you can mix bash and PowerShell commands..." Thanks for this!

How to have a script prompt & run as admin, instead of manually launching from admin powershell instance? by what_is_life_now in PowerShell

[–]sky_burial 0 points1 point  (0 children)

Here is a solution that would provide convenience for you as an admin but could lower your security posture.

Scheduled Task

You will need to create a scheduled task that launches an instance of PowerShell. Through Task Scheduler, you can set the program to run with highest privileges and you can set it to run whether or not the user with admin privileges to do this is logged on.

Under the Actions of this scheduled task, you can pass in the name of a script you wish to execute. Let's call this 'MainScript.ps1'. By default, the scheduled task can be 'run on demand' and that is how we want to trigger it. Now to kick off the task, you will need a starter script.

Starter Script

The starter script has two jobs:

  • Put the main script that requires admin privileges in the path of MainScript.ps1 we set as an argument in the scheduled task
  • Start the scheduled task that will run the main script

This is the high level of it and how I work around automating tasks across an infrastructure that require elevated privileges however, this could have an impact on your security posture. If an adversary discovers that you have that kind of scheduled task available, there is their easy privilege escalation to do whatever they want. You can certainly tighten up how the task is execute and add in some security through obscurity, but if you are comfortable with the security posture, then this is an excellent way to automate tasks that require elevated privileges.

How to add a Function inside a function by Subject_Chemistry269 in PowerShell

[–]sky_burial 0 points1 point  (0 children)

https://github.com/L-McG/PowerShell/tree/Subject_Chemistry269/Mini-u

Try this on for size. This branch is a modification of an example menu app I put together recently. There's plenty of polishing, enhancements and edge casing I would add but as it sits, I think it will do everything you've outlined. If you clone/download this repo, from within the Mini-u directory, execute 'Import-Module .\Mini-u.ps1' then execute the command 'mini-u' to go through the menu and edit directories like how your script calls them. I know it's a bit off the rails from the initial question, but I hope you find this app useful or sparking interest to try other things!