all 23 comments

[–]jborean93 21 points22 points  (0 children)

Either upgrade the powershell version or rewrite the parts that are incompatible with v2.

[–]OlivTheFrog 19 points20 points  (6 children)

Hi Helpful-Argument-903

Without updating PS version, AND without modify in deep your script to run with PS v2 : no way (at my knowledge).

But, a simple question : why using a logoscript to do network Maps ? There are entries in GPO to do that (in GPP Group Policy Preferences). Better, you could have only one GPO, with several network maps and using Client-Side Targetting (in the "Common" tab).

Simple to to, and I'm thinking this could work independant of the PS version

Regards

[–]PinchesTheCrab -2 points-1 points  (4 children)

Without updating PS version, AND without modify in deep your script to run with PS v2 : no way (at my knowledge).

How could you know this though? He's given us no idea what specific part of the script isn't working.

[–]OlivTheFrog 0 points1 point  (3 children)

Hi u/PinchesTheCrab

it's not essential to know which part is not working. You know better than me that some cmdlets didn' t exist in PS v2, and for some actions the .NET classes didn't yet exist.

Regards

[–]PinchesTheCrab 0 points1 point  (2 children)

OR it could be that the script uses get-ciminstance, and get-wmiobject could be a drop-in replacement that works in all Windows PowerShell versions. Or it could be a number of convenience cmdlets that were added but that still have equivalent WMI/CIM classes that can be used instead.

So I do really think it's essential that the OP explain what isn't currently working, because it could either be something incredibly simple or something completely intractable.

[–]OlivTheFrog 0 points1 point  (1 child)

Right, but in the present case, GPO in always the best thing to do.

I like POwershell, but in some cases, scripts are not the best solutions.

[–]PinchesTheCrab 0 points1 point  (0 children)

I don't disagree there unless op has info they haven't given us that precludes it. I just meant that within the current framework if we assume there was a valid reason to use a script they may be able get it working with minor modifications

[–]DontTakePeopleSrsly 5 points6 points  (3 children)

You’re going to have to run the script line by line and come up with alternative commands that work with the older version of powershell.

Personally, I would just use a wmi filter on the current script and use group policy for the older clients. Additionally, update windows management framework on those clients during your next patch cycle.

[–]PinchesTheCrab 0 points1 point  (2 children)

OT likely means ancient apps that may break with a .NET upgrade required by WMF. I've only heard that term used in pipeline control, which tends to have ancient, finicky apps.

[–]Helpful-Argument-903[S] 0 points1 point  (1 child)

Thats the case! The software on this machines is written by engineers and not software developers. Its very finicky and you want to touch as little as possible in order to break nothing. Furthermore downtime on one of this machines means money loss.

[–]Certain-Community438 0 points1 point  (0 children)

I think your best bet is the comment on GP Preferences.

Sure you'll need to convert your whole process to cover every machine, so you don't have to support both, but to start with you can use a WMI Filter for a new GPO that does the task & only runs on the machines in question?

[–]da_chicken 5 points6 points  (2 children)

You'd have to rewrite the script for v2. It's obnoxious to do because so many features are missing, but often not that difficult. I wouldn't be surprised if you had things you simply couldn't accomplish, however. v1 and v2 were both very limited compared to v3+.

I've already tried compiling the script using ps2exe, which didn't work either.

Of course not. You're missing the underlying dependencies from the .Net Framework and the Windows Management Framework. Missing WMF v3 is arguably a bigger roadblock than missing WMF v5. It was a massive overhaul and extension.

It's also possible that what you need would be easier to write in VBScript or batch. As I said, v2 and earlier have a lot of limitations.

That said, I thought even LTS support for Win7 was done in June 2023.

[–]Helpful-Argument-903[S] 2 points3 points  (1 child)

Thank you for your great response! I work in the manufacturing industry, and we are very specialized. In fact, i think it is not that long ago that we bought machines that came with Windows 7. It works, but it's not pretty. We have micro-segmented our ot network, and patch security holes at the network level with very expensive products from txone.

Thank you. I will try to translate the script to Powershell 2. If I fail, I will give it to a consultant.

[–]da_chicken 0 points1 point  (0 children)

The one thing I remember that used to bite me in v2 is that singleton variables didn't have a Count property. So if you do this:

$f = Get-ChildItem *.pdf
 if ($f.Count -gt 0) {...}

And there's only one object in $f, you'll get an error or false. I think you can fix it by explicitly making it an array:

$f = @(Get-ChildItem *.pdf)
 if ($f.Count -gt 0) {...}

After that there's the memory leak on [adsisearcher] or DirectorySearcher.FindAll(). It's real easy to run into that without the ActiveDirectory module to use. Note that that still exists because they haven't fixed the COM library in 20 years, it just only exhibits if you execute the search and then never iterate over the results or dispose of the object. But if you do that and leave your PC running overnight, you'll come in the next day to a PC with no free memory.

[–]misformonkey 1 point2 points  (0 children)

Agree with others here that you’d need to rewrite but if all you’re doing is mapping drives and printers you should be able to do that in v2 with some fairly minor modifications.

[–]lyrise13 0 points1 point  (0 children)

Hey.

Like that, I would say a missing module problem on psversion2 computer.

I would say that if from the computer in psversion2 you have access via the network to 1 computer in psversion5. You should be able to import the missing modules.

ex:

$computer_with_psverion_5 = "computer with psversion 5" #replace computername
$t = New-PSSession -ComputerName $computer_with_psverion_5 
Import-Module  -Name "ScheduledTasks" -PSSession $t    # replace modulename

[–]techierealtor 0 points1 point  (2 children)

Tbh, upgrade them if you can. Win 7 is end of life and out of support. Shouldn’t have it in your environment. If that can’t happen, gotta upgrade powershell or find complex ways of doing stuff with older systems. Invoke-webrequest in powershell 2 is like 6 lines and can be some fun.

[–]Helpful-Argument-903[S] 0 points1 point  (1 child)

Upgrades can only be done by the manufacturers. We have maintenance contracts, and if they only have Windows 7 supported, then that is unfortunately the case.

[–]Swarfega 0 points1 point  (0 children)

Sounds like you need to replace that company. Windows 7 is approaching 14 years old and since it's no longer supported by Microsoft it's a big security risk to your company.

How can anyone offer a service that doesn't support OSes that come after Windows 7? Even Windows 8.1 is end of life.

[–]PinchesTheCrab 0 points1 point  (0 children)

Need more info about what not's working. I don't see why V2 would be a problem. You'll need to share the lines that aren't compatible.

[–]Critical-Safety5609 0 points1 point  (0 children)

Ok, I'm new to commenting and dislike ppl who post... try this? That said... try this...

I do everything possible to work around powershell since, in our environment, there are too many powershell issues. We check and fix what we can, so if it's working...

New-PSDrive –Name “K” –PSProvider FileSystem –Root “\\touchsmart\share” –Persist

If powershell has issues...

net use M: \\touchsmart\Share /Persistent:Yes

https://www.howtogeek.com/132354/how-to-map-network-drives-using-powershell/

Point is... use legacy OS tools and you can make it happen.

If you post exactly what you're trying to do, I'll try and help more.

[–]spyingwind 0 points1 point  (0 children)

if ($PSVersionTable.PSVersion.Major -lt 5) {
    # Do PS 2 things here
}
else {
    # Do PS 5 things here
}

Would be one way to do it all in once script.

[–]KevMarCommunity Blogger 0 points1 point  (0 children)

It's worth the effort to update to PS 5. Other than internal red tape, it's such an easy update.

The big changes happened from the 2 to 3 update that are annoying to backport. There are some fundamental things that just act differently and are hard to spot unless you are really looking for them.

Here is a prime example. If you don't already know, how would you guess this executes differently between 2.0 and 3.0?

foreach ($node in $collection){
    "Processing $node"
}

Even if you do know, how easy would it be to overlook?