goss34 1 Posted October 3, 2011 (edited) Hi Guys, I currently have this working line: RunWait(@ComSpec & ' /c ' & 'wmic /node:' & $PC1 & ' ComputerSystem Get UserName | find "username" > C:\LoggedOn.txt', "", @SW_HIDE) I want to change it to use the variable in the text file name too but i cant get the syntax right! I have tried various combinations but am getting nowhere! Latest attempt: RunWait(@ComSpec & ' /c ' & 'wmic /node:' & $PC1 & ' ComputerSystem Get UserName | find "username" > C:\' & $PC1 & 'LoggedOn.txt', "", @SW_HIDE) It looks ok but the text file doesnt get written. Can someone help correct me please? Thanks Edited October 3, 2011 by goss34 Share this post Link to post Share on other sites
iamtheky 927 Posted October 3, 2011 (edited) $PC1 = "LOCALHOST" runwait (@ComSpec & " /c wmic /node:" & $PC1 & " /output:c:\" & $PC1 & "_Logged_On.txt ComputerSystem Get UserName") Edited October 3, 2011 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Share this post Link to post Share on other sites
goss34 1 Posted October 3, 2011 Hi Boththose, That gives me the correct filename but because i have lost the " | find" now the output from the command cant be read properly by my next line. Any ideas how i can include the find in the new string? (I dont fully understand how what you have done is working so am struggling to adjust it). Thanks Share this post Link to post Share on other sites
iamtheky 927 Posted October 3, 2011 (edited) my first used the wmic output switch to create the file. This is how you would do it with pipes, i went ahead and added the switches on the find command to ignore case sensitivity and find everything that wasnt the string "username" resulting in a text file with domain/usernames, which i assume is what the remainder of your script is after...but not breaking the rest of your script without posting it or detailing exactly what is needed will be wholly dependent on your luck. $PC1 = "LOCALHOST" runwait (@ComSpec & ' /c wmic /node:' & $PC1 & ' ComputerSystem Get UserName | Find /i /v' & '"username"' & ' > ' & "c:\" & $PC1 & "LoggedOn.txt") Edited October 3, 2011 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Share this post Link to post Share on other sites
goss34 1 Posted October 4, 2011 my first used the wmic output switch to create the file. This is how you would do it with pipes, i went ahead and added the switches on the find command to ignore case sensitivity and find everything that wasnt the string "username" resulting in a text file with domain/usernames, which i assume is what the remainder of your script is after...but not breaking the rest of your script without posting it or detailing exactly what is needed will be wholly dependent on your luck. $PC1 = "LOCALHOST" runwait (@ComSpec & ' /c wmic /node:' & $PC1 & ' ComputerSystem Get UserName | Find /i /v' & '"username"' & ' > ' & "c:\" & $PC1 & "LoggedOn.txt") Hi Boththose, Excellent, that line works nicely now What i am using this line for is to basically to find out if a PC has someone logged on or not, i am not sure how i am going to do it yet but if i can generate a text file with a username in it then i want to read that file and if a username exists use the corresponding $PC* variable to write that into a GUI with an available flag at the side of it. Additionally to this there will be a button for "connect" that will connect 1 of the users to a free PC using RDP. I have the connection to an RDP session in a GUI with some help from one of the MVP's on here but now i need to populate the GUI with the extracts from this script. I hope all that makes sense for you to read. Thanks for your help Share this post Link to post Share on other sites