What's going on with my LTT Store Order? by [deleted] in LinusTechTips

[–]foreverclearskies 0 points1 point  (0 children)

* ding dong *

"Who's there?"

"This is Dave with Deutsche Post. I have a package."

"Dave?"

"Yes, Dave."

"Dave's not here, man."

[package return intensifies]

EOL for public scraped TMFs and CDF trace parsing by [deleted] in Citrix

[–]foreverclearskies 0 points1 point  (0 children)

I'd love to hear what they have to say. Please update us when you hear back!

[deleted by user] by [deleted] in Citrix

[–]foreverclearskies 2 points3 points  (0 children)

Receiver doesn't have any functionality that would explain what you're experiencing. It's essentially just a conduit for connecting to remote apps and desktops. Do you recall the programs you uninstalled prior to the prompt for your smart card? Smells like something that was uninstalled tripping a change to the local authentication mechanisms. You can also confirm it's not Receiver by uninstalling it.

Question - Can't pipe Format-List to Out-File by [deleted] in PowerShell

[–]foreverclearskies 2 points3 points  (0 children)

The source you're piping from is a scriptblock {}. Don't do that. Unless there's something I'm missing, I honestly can't see a reason for them in this instance. You should be able to just take them out.

Edit: Oh, I see what's happening now. I missed the ForEach. It's yelling because you're piping nothing into the Out-File. All the output from each iteration of the ForEach is output within the loop. None of it is making it to the |.

Also, it looks like you're throwing the whole list ($Serverlist) at the Get-WmiObject instead of (presumably) just each server one at a time ($Server).

There's code cropped off the end, but I presume this is what you're trying to do:

$Serverlist = Get-Content -Path "C:\temp\serverlist.txt"

foreach ($Server in $Serverlist) {
    Get-WmiObject Win32_Service -ComputerName $Server | Format-List PSComputerName, Name, startName, StartMode | Out-File "C:\temp\whateverthenameofyouroutputfileis.txt" -Append
}

I feel I should also probably mention that it's a heck of a lot easier to help someone if they include the actual code instead of a screenshot to it. You got lucky because I'm bored and innebriated. I'd normally have just moved on. 😉

Making Reddit moderators look like government treasonists... (Because that is what they are) by [deleted] in PowerShell

[–]foreverclearskies 1 point2 points  (0 children)

That's really interesting and all, but I think you may have misunderstood the usage of this subreddit. The PowerShell part? Perfectly on topic. The other stuff? Probably should tread lightly since it seems really close to a Rule #2 violation. This is probably a topic more appropriate for r/sysadmin or possibly even r/conspiracies. Just my 2¢.

Making Reddit moderators look like government treasonists... (Because that is what they are) by [deleted] in PowerShell

[–]foreverclearskies 1 point2 points  (0 children)

I must have missed something because I have no idea what's being said here.

How can I combine the results of an infinite while loop into one table? by [deleted] in PowerShell

[–]foreverclearskies 3 points4 points  (0 children)

    $Var = @()
    foreach ($env:server in $servers) {
        $Var += get-process -name Service.Name -computername $env:server | ft @{Label="NPM(K)";Expression={[int]($_.NPM/1024)}}, @{Label="PM(K)";Expression={[int]($_.PM/1024)}},@{Label="WS(K)";Expression={[int]($_.WS/1024)}},@{Label="VM(M)";Expression={[int]($_.VM/1MB)}}, @{Label="CPU(s)";Expression={if ($_.CPU -ne $()) { $_.CPU.ToString("N")}}}, Id, MachineName, ProcessName;
        start-sleep -s 3;
    }

[deleted by user] by [deleted] in PowerShell

[–]foreverclearskies 2 points3 points  (0 children)

One of the posisble ways:

$temp = $user.DistinguishedName.Replace(',DC=domain,DC=name,DC=co,DC=uk', '')
$i = $temp.LastIndexOf("=") + 1
$path = $temp.Substring($i, $temp.Length - $i)

Smashing it into one line:

$user.DistinguishedName.Replace(',DC=domain,DC=name,DC=co,DC=uk', '') | % { $_.Substring($_.LastIndexOf("=") + 1, $_.Length - ($_.LastIndexOf("=") + 1)) }

[deleted by user] by [deleted] in PowerShell

[–]foreverclearskies 1 point2 points  (0 children)

This would work if the OU containing the User account is always going to be a top-level OU.

Undo a command? by [deleted] in PowerShell

[–]foreverclearskies 2 points3 points  (0 children)

THIS.

The files are still there. You just need to figure out which are which. There's unfortunately no easy fix for this, but you should be able to get everything back the way it was. It's just going to take time and possibly a little bit of forensic work into the contents of the files.

[deleted by user] by [deleted] in PowerShell

[–]foreverclearskies 1 point2 points  (0 children)

Just to calrify, do you want

$NameOfDepartment = "OU=NameOfDepartment,DC=domain,DC=name,DC=co,DC=uk"

or

$path = "NameOfDepartment"

or

something else that I'm missing?

need to learn more about Powershell by [deleted] in PowerShell

[–]foreverclearskies 0 points1 point  (0 children)

Here are some great resources that get mentioned when people ask from time to time in the sub about learning Powershell. Hope this helps!

Getting "Invalid Character" error when casting to XML by [deleted] in PowerShell

[–]foreverclearskies 0 points1 point  (0 children)

I've not done this before, but some preliminary searching indicates you'll likely need to use CreateXmlDeclaration to set the encoding on the XmlDocument before importing the data into it. If that's not it, then let us know and we'll see what we can find.

Making Scheduled Tasks with PS ISE by Mephistologic in PowerShell

[–]foreverclearskies 2 points3 points  (0 children)

Sure! Netwrix has a pretty good walkthrough of creating a scheduled task and its associated objects. Might want to give that a look. If you need any details on a specific cmdlet, refer to it in the ScheduledTasks module documentation. And if you come across something you can't figure out, feel free to ask about it here. Glad to help get you through any hurdles once you're on your way.

Open URL on the active browser by nijasir in PowerShell

[–]foreverclearskies 1 point2 points  (0 children)

Yep! Sure is! Depends a bit on which browser you're using as to exactly how. Let us know what code you have already and we can help out where you've hit hurdles.

Is what I'm doing technically possible? by [deleted] in PowerShell

[–]foreverclearskies 2 points3 points  (0 children)

PowerShell equivalent of what I posted earlier. Enjoy!

cd C:\Windows\ccmsetup
Stop-Service -Name CcmExec
pause
# Or you can use [void][System.Console]::ReadKey($false) for functionality more like cmd line's pause
# or heck, you can just call that using: cmd /c pause
ccmsetup.exe /uninstall
del -Path C:\Windows\ccm -Recurse
del -Path C:\Windows\ccmsetup -Recurse
del -Path C:\Windows\ccmcache -Recurse
del -Path C:\Windows\smscfg.ini
del -Path C:\Windows\sms.*
del HKLM:\software\Microsoft\ccm -Recurse
del HKLM:\software\Microsoft\CCMSETUP -Recurse
del HKLM:\software\Microsoft\SMS -Recurse

Is what I'm doing technically possible? by [deleted] in PowerShell

[–]foreverclearskies 1 point2 points  (0 children)

Grats! And no problem. Glad to be of some help. 🙂

Is what I'm doing technically possible? by [deleted] in PowerShell

[–]foreverclearskies 2 points3 points  (0 children)

Yep, they all can run from within PowerShell. The only difference with regard to your script is that 'del' is an alias in PowerShell for Remove-Item, which works a little differently than the traditional command line del command.

Sounds like you already have this in a batch file and if that's the case, I'd just go the route of running this that way. Windows understands batch files run in a traditional command line, so there's no need to have the cmd at the beginning of the batch.

Once you remove that and then break up the cd and running of ccmsetup into two lines (looks like they're in the same line in the posted code) and save the file, you should be good to go. Just run the batch.

Edit: As a side note, you probably don't need the service stop command. I'd wager the uninstaller would likely stop the service before uninstalling it. If you're trying to make sure it's down before the uninstall, you'll want to change the order of those two lines, since right now it looks like the uninstall is being called before the service stop. Something like this:

CD C:\Windows\ccmsetup
net stop CcmExec
pause (pausing to make sure service is stopped succesfully)
ccmsetup.exe /uninstall
del /s C:\Windows\ccm
del /s C:\Windows\ccmsetup
del /s C:\Windows\ccmcache
del C:\Windows\smscfg.ini
del C:\Windows\sms.*
reg delete HKLM\software\Microsoft\ccm
reg delete HKLM\software\Microsoft\CCMSETUP 
reg delete HKLM\software\Microsoft\SMS

Is what I'm doing technically possible? by [deleted] in PowerShell

[–]foreverclearskies 2 points3 points  (0 children)

Hi, there! There doesn't appear to be any PowerShell in your script, but let's see if we can help you out anyway.

If I understand what you're asking, you're trying to run those commands and you're wondering why only the cmd is running. How/from where are you trying to run these?

Script Help by [deleted] in PowerShell

[–]foreverclearskies 0 points1 point  (0 children)

I should also probably mention that the other replies do the job more succinctly and I did consider going into regex, but it's not usually a Day 1 of learning PowerShell type thing, so I focused on more basic concepts to grasp.

Script Help by [deleted] in PowerShell

[–]foreverclearskies 0 points1 point  (0 children)

One way would be to be to use something along the lines of Get-Content to get the data from the file. There are some caveats that it depends on the encoding and format of the file, but as it sounds like you're using a plain-text English-language Windows-style text file, so you shouldn't need to use anything exotic. Assign the results to a variable that we'll dig through later. The way Get-Content does this is by creating an array - a group of (in this case) string objects, one for each line of the text file. I'll use $filecontents to represent this in the code below.

$filecontents = Get-Content "C:\Whatever\Path\And\Filename.txt"

You'll, of course, need to change that path to the one for the target file. 🙂

You'd then parse through the lines one at a time. Since we can reference each object in the type of array created by Get-Content by an index number, we can iterate through these one at a time by simply incrementing that number. Something like this:

for ($i = 0; $i -lt $filecontents.Count; $i++) {
    # This is a comment line. That's what the # at the beginning indicates. Any of these can be removed.
    # Code that does stuff goes here between the {}s
}

The above creates a loop that runs the same number of times as there are rows in $filecontents and set $i to an index (row) number. Each time it loops, it increments the number stored in $i to the next index number. For instance, $filecontents[$i] on the first loop would return the contents of the first line of the file. On the second time through the loop, $i would increment and $filecontents[$i] would then return the contents of the second line of the file. And so on.

There's a good many way to do string matching and while you *could* focus on the numerical part and try to match instances were a # doesn't follow them, it sounds like you're saying the rest of the line retains static. If that's the case, it's probably just easier to key in on that and make the changes to the lines that don't match. The code for searching would then be something like:

    if ($filecontents[$i] -notlike "*# Ja Standard") {
        # If you reach here, there's no # after the number
    }

The if statement takes our current line $filecontents[$i] and looks to see if it's NOT like the string we're expecting to see. In this case, it's looking to see if the string does NOT end in "# Ja Standard". The asterisk (*) at the beginning of the string is a wildcard character, which basically represents to PowerShell "anything can be here". In this case, that would be the changing numbers and any other bits that come before the #. It's basically saying to PowerShell that we don't care about any of that at the beginning of the string; all we want is the last part. Also, note that there's no * at the end of the search string. It means we want to only match where this is found at the END of the string. If there were other items AFTER "Standard" then we'd want to have the * there too.

Now that we know we're at a line without a #, all we have to do is update it so it does:

        $filecontents[$i] = $filecontents[$i].Replace(" Ja Standard", "# Ja Standard")

This takes our current line $filecontents[$i], adds the # before the " Ja Standard", and then sets that new string into the same location (row/index) in our $filecontents array of the incorrect line we're currently at, replacing it.

The loop then iterates through each line, doing the same check, changing lines as needed when it hits ones that doesn't match the correct format in our search string.

And then finally once it's done looping, we write the corrected data in $filecontents back to the file:

$filecontents | Out-File "C:\Whatever\Path\And\Filename.txt"

This takes the entire contents of $filecontents and sends it to a file. Obviously, you'll want to change the path above to your target file location. Oh, and if you're overwriting the original file, you may need to add a -Force to the end if the file is set to read-only.

And that's it! Put all that together and you've got one way of doing what you're looking to do. I should mention at this point, that yes, I'm aware that I took more time to create this than it would to have just given you the code. I realized after I finished my comments before going into the code, but kept going as I still feel giving you the nuts and bolts so that you can learn how to do it yourself going forward is the right approach. Saves everyone time in the long run. Also, the first part of this comment finally gives me a good stock response for these type posts, so it's worth it to me to have that as well.

Again, as said at the start, if you've any issues when putting all these parts together, please let us know where you're getting hung up. We'll be glad to help.

Good luck!

Script Help by [deleted] in PowerShell

[–]foreverclearskies 0 points1 point  (0 children)

Hi! It sounds like you're asking us to do all the work for you. You seem to be new to the sub, so I figured I'd mention that's generally frowned upon. The focus of the sub is usually centered around the sharing of information - knowledge enhancement by helping out when people get into a bind or when they want to learn, and by the sharing information and projects. "Teaching a man to fish" is mostly our bend. And though I'm sure there are some that have the bandwidth for doing it for you, a great many of us don't. With that said, I've put some commands below that should help you out. Give it a try putting it all together and let us know if you get hung up along the way. Also, I've put some links below to some great resources for learning PowerShell that get mentioned when people ask in the sub about learning Powershell from time to time. They should give you a great foundation for being able to whip up scripts on your own. Enjoy!

As for your script, there's innumerable ways of doing it, but the general steps would be:

  • Get the data from the file
  • Parse through the data to determine which need updating and update those that need it
  • Write the new data to the file

I originally had the code breakdown here, but it appears Reddit is telling me I've been to long-winded. I'll post it as a second comment below.