Indeed the creation of the necessary escaped line feed can be simplified. @echo off (set \n=^^^ %= This creates an escaped Line Feed - DO NOT ALTER =% ) PowerShell -Command ^& { %\n% # This is a comment %\n% Get-Service %\n% } pause You can read up in this thread https://www.dostips.com/forum/viewt...
The # comment does not work the way you did, because it's a line comment, and the PowerShell command you generated was all on one line for PowerShell. To use such a line comment, you need to generate a PowerShell script that contains multiple lines. This is akin to what we do for generating multi-l...
Is there a way to write a comment in powershell, but in a batch script? Unfortunately I can't use polyglot for this. Example that doesn't work, but to show the idea powershell -command "& {"^ #this is a comment Get-service^ "}" I can only get the comment to work if I use a comment block, but I don't...
Currently I'm logged in as User1 and User2 is disconnected. When I run the script this is the results I'm getting: USER1 is logged on USER1 is not added USER2 is logged on USER2 is not added PROFILE[0]=USER2 PROFILE[10]=USER1 PROFILE[11]=USER3 PROFILE[1]=USER4 PROFILE[2]=USER5 PROFILE[3]=USER6 PROFI...
Hm....I just realized I didn't explain fully. The results of the array should not have any duplicate users. So I have a list with only 1 instance of the users logged on in the list and duplicates of users not logged in. So the list should be of only users not logged onto the computer. Is this possib...
Firstly the code you have above has unbalanced parentheses and it also is performing case sensitive comparisons. @ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION SET "a=0" SET "b=0" FOR %%a IN ("%USERPROFILE%") DO ( ECHO %%~nxa is logged on FOR /F %%c IN ('DIR/B/AD-S-H C:\Use...
I'm wondering how do you compare the results from one array to another? I'm trying not list users that are not logged in at the moment and then put the results in an array. @ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION SET "a=0" SET "b=0" FOR /F "SKIP=1 TOKENS=1 DELIMS=> " ...
I'm trying to expand 2 variables at the same time. Is this possible? The issue I'm having is during the IF statement. Instead of echoing 1 and then 2, the script echos 1 and 1. SETLOCAL ENABLEDELAYEDEXPANSION SET i=0 SET ARR[%i%]=1 SET /A "i+=1" SET ARR[%i%]=2 SET /A "i+=1" SET A...
I'm trying to figure out why the SET command in an IF statement will not change. The script just displays the IP address, subnet mask, and gateway. It also logs the results in a txt file. :@echo off SETLOCAL ENABLEDELAYEDEXPANSION SET LOG="C:\LOGS\IPMATCH.TXT" SET "i=0" ::STORE F...