Search found 11 matches

by ImAhNoBoDy
11 May 2020 05:49
Forum: DOS Batch Forum
Topic: Way to save a /p to a new .txt file?
Replies: 3
Views: 3639

Re: Way to save a /p to a new .txt file?

Something like this?

Code: Select all

@echo off
echo user response
set /p "a="
echo %a% > newtxt.txt
by ImAhNoBoDy
09 May 2020 21:07
Forum: DOS Batch Forum
Topic: Powershell comment
Replies: 7
Views: 6053

Re: Powershell comment

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...
by ImAhNoBoDy
09 May 2020 11:10
Forum: DOS Batch Forum
Topic: Powershell comment
Replies: 7
Views: 6053

Re: Powershell comment

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...
by ImAhNoBoDy
07 May 2020 21:12
Forum: DOS Batch Forum
Topic: Powershell comment
Replies: 7
Views: 6053

Powershell comment

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...
by ImAhNoBoDy
06 Dec 2016 11:41
Forum: DOS Batch Forum
Topic: Comparing Arrays
Replies: 9
Views: 6152

Re: Comparing Arrays

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...
by ImAhNoBoDy
06 Dec 2016 10:18
Forum: DOS Batch Forum
Topic: Comparing Arrays
Replies: 9
Views: 6152

Re: Comparing Arrays

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...
by ImAhNoBoDy
06 Dec 2016 06:44
Forum: DOS Batch Forum
Topic: Comparing Arrays
Replies: 9
Views: 6152

Re: Comparing Arrays

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...
by ImAhNoBoDy
06 Dec 2016 05:03
Forum: DOS Batch Forum
Topic: Expand 2 variables at the same time
Replies: 5
Views: 6182

Re: Expand 2 variables at the same time

The solution was to replace ECHO !ARR[%i%]! with CALL ECHO %%ARR[!i!]%%
by ImAhNoBoDy
06 Dec 2016 04:54
Forum: DOS Batch Forum
Topic: Comparing Arrays
Replies: 9
Views: 6152

Comparing Arrays

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=> " ...
by ImAhNoBoDy
16 Nov 2016 16:18
Forum: DOS Batch Forum
Topic: Expand 2 variables at the same time
Replies: 5
Views: 6182

Expand 2 variables at the same time

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...
by ImAhNoBoDy
16 Nov 2016 12:31
Forum: DOS Batch Forum
Topic: SET variable in IF statement
Replies: 2
Views: 2822

SET variable in IF statement

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...