Change Environment Path and MAKE IT STICK
Reddit » PowerShell
by /u/stignewton
8h ago
Hi all, We've got an odd issue where random machines (all Win11) cannot run Winget, even though it's installed. I've identified the cause as being Winget isn't included in the PATH environment variable. Now I've got a script written for this (as an Intune Remediation), but in testing this won't stick. Found an article about setting this to the Machine context, but not sure if I'm doing it right because it still won't goddamned stick. Script below - can anyone assist with this? # Get winget path into variable $wingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstall ..read more
Visit website
Scripting help for ForceChangePasswordNextSignIn in 365
Reddit » PowerShell
by /u/xbgt1
8h ago
I have the following for when I need to change a users password on next login for 365 rather than having to reset it and contact them. ​ $PasswordProfile = @{ ForceChangePasswordNextSignIn = $true } Update-MgUser -userid USER@DOMAIN.com -PasswordProfile $PasswordProfile ​ ​ I am trying to do this from a csv such as below but I'm lost. Any pointers would be appreciated ​ $Resetpassword = Import-Csv "C:\Scripts\expired.csv" $PasswordProfile = @{ ForceChangePasswordNextSignIn = $true } foreach ($SamAccountName in $Resetpassword) Update-MgUser -userid $SamAccountName -PasswordProfile $PasswordPro ..read more
Visit website
How can I escape a character that was imported from a csv, piped to a variable, inside another variable?
Reddit » PowerShell
by /u/Odd_Efficiency4730
8h ago
I have a list of names and a handful of them have a single quote somewhere in their names. For example, "John D'Var" The list is in a csv file which I imported into Powershell via variable. The file location was also made into a variable. So it would be like: $location = C:\some\location\file.csv and $list = Import-Csv $location. I then needed to run these in another database via Microsoft Graph to check if they are in there. So I used a ForEach ($name in $list){ $emailaddress = $name.emailaddress $findname = Get-MGUser -Filter "Mail eq '$emailaddress'" } However, it still came out as an erro ..read more
Visit website
Thought I was smart putting powershell in a batch but it got instantly detected on the client's computer
Reddit » PowerShell
by /u/Bratman117
8h ago
Engineered this line and thought it looked good, but now the file got detected by the client's kaspersky and I was wondering if you guys have found any way to have only one batch-powershell file that doesn't get detected by an av? Considering you can double juste double click one and go fuck yourself explaining the other one with execution policies... I even checked in VirusTotal but it doesn't find anything with either .bat or .ps1 extension The line in question btw: # 2>nul & echo off & cls & PowerShell -NoP -NoL -EP Bypass -C "$s='%0.ps1';gc '%0'>$s;.$s %*;rm $s" & ex ..read more
Visit website
Script Only Partial Working
Reddit » PowerShell
by /u/intravenous_therapy
8h ago
Hello all. I'm writing a PS script to rename the computer name of an AWS EC2 instance to the instance ID (which it pulls from the instance metadata). The script then joins the computer to the domain, adds admin users, and sets user logon permissions. I know the limit of 15 characters on the hostname, and took care of that issue. The problem is that it seems that phase 1 isn't working when run from the same script as phase 2. It works fine if I separate it out, which I don't really want to do. ​ ##-----------------------PHASE1-SET COMPUTER NAME------------------------## #Get API Token to Call ..read more
Visit website
Tee causing incorrect order of writes and reads... I think.
Reddit » PowerShell
by /u/Velmeran_60021
8h ago
I'm trying to help the QA person on my team at work. They're trying to write automated tests for a CLI tool we have to write for our customer. Capturing what's written to the screen to verify the CLI Tool is working the way it's supposed to is proving to be a pain. But I remembered something from Unix called Tee and found that there's a port in PowerShell for that... so we could just have all the text get saved in a file that could be parsed to verify it's doing what it's supposed to. I wrote a simple executable to test Tee. It writes a couple lines and then begins a loop where it uses Consol ..read more
Visit website
Looping Until Condition is Met or Max Loops Reached
Reddit » PowerShell
by /u/digitalnoise
14h ago
I am working on a project where I need to check a remote SFTP site and see if files are available and if not, sleep and then check again, up to a maximum number of cycles. If the files are available - or become available during the check cycle - I need to proceed with downloading them. I think I have the logic built correctly, but I could really use another set of eyes. Parameter Value $fcount Returned from call to the Get-SFTPCount function. $ExpectedCount 8 $LoopCnt Initialized at 0 $MaxLoops 5 Code: # Bunch of prep work stuff above here - function and parameter definitions ..read more
Visit website
Check if a GPO is open in editing by anyone
Reddit » PowerShell
by /u/darkrhyes
14h ago
We have several people who can edit certain low-level GPOs just to delegate some simple tasks. However, these folks don't talk with each other, and we frequently have GPOs where two or three of them have the GPO open for editing. When one makes a change and tries to Apply it, they get an error about access denied. I need to find a way to check if the GPO is open in editing mode by another user. Not sure if there is a file handle for it in the SYSVOL or if something exists in GPMC. Maybe a way to check if GPMC is open by any logged on user to our admin servers. submitted by /u/darkrhyes [visi ..read more
Visit website
AD User creation error driving me nuts
Reddit » PowerShell
by /u/Chryses3
14h ago
Hey Reddit, Currently stuck on an issue that's been bothering me this entire day. Relatively new to PS scripting, and my first venture into it has been a very basic account creation script. The script does the following: Grab UPN from terminal From UPN provided, search and load AD user into variable Grab several values from user, populate into hashtable to display to user (mainly to make it readable for me lol) From these values, generate an account. The first steps work as they should, and the script does generate accounts, however, these have nothing passed thru the name parameter ..read more
Visit website
Need help with troubleshooting GPG powershell script.
Reddit » PowerShell
by /u/Lost-Box7882
14h ago
I honestly have very little to no idea how to use powershell scripts and I've been racking my brain for hours trying to get this to work. Essentially I have a watcher on a folder that triggers every time a new file gets added to it. It then encrypts the new file through GPG (another thing I have very little experience with). It sounds so simple but some of this just doesnt make sense without someone teaching me Essentially this is what I have # Define the directory to monitor $directoryToWatch = "C:\Users\Documents\trialrun" # Function to encrypt a file using gpg function Encrypt-NewFile { p ..read more
Visit website

Follow Reddit » PowerShell on FeedSpot

Continue with Google
Continue with Apple
OR