Creating Variables From Text File

Hello a little new to powershell and have banging my head on the wall trying to get this working.
I have a text file (where the numbers of lines will change everytime) that will contain AD groups. 
Lets say it looks like this
GroupA
GroupB
GroupC
I'm trying to you a loop that will read the file and output each new line to a variable so
var1=GroupA
Var2 =GroupB
Var3=Groupc
My first problem is that non of these can be null since this will be then be used with Add-ADgroupmemeber
So I have it get the number of items with $Items = get-content *File* | Measure-Object -Line
After that I have been trying to use a loop which to me looks like it should work however is not. I'm not getting any errors. However I'm not getting any created variables either. 
For ($i=1; $i -lt $Items.lines; $i++) {
$var[$i] = (Get-Content *File*)[$i-1]
write-host $var[$i]}
In my head I should get a listed of each line of the txt file but I'm getting nothing. 
In the end I was hoping to doing something along the lines of ADD-Adgroupmember -identity $Var[$i] -members *Machine Name*
If there is a better way to approach this I'm all ears.
Thanks for any help!

You don't need a loop to read each line from the file. You don't need a variable for each group read from the file. 
For example, if your file looks like:
GroupA
GroupB
GroupC
with spaces/empty lines in it, that you wish to ignore, you can use:
$Groups = Get-Content .\groups2.txt | % { ($_.split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)) }
The $Groups variable will be an array that holds non-empty lines from the file. You can use that directly as in:
foreach ($Group in (Get-Content .\groups2.txt | % { ($_.split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)) })) {
Add-ADGroupMember -identity $Group -members *Machine Name*
Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________
Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

Similar Messages

  • How to create PDF from text file with specific layout?

    I wanted to create the pdf from text file in specific layout - Landscape orientation and JIS B3 Page size while at Adobe Acrobat Pro.
    In past, I could do a right click on a text file (desktop area) and select print to print out the document into .pdf BUT only if I set the Adobe PDF to Landscape and JIS B3 Page size BEFORE.  And I could only do 15 text documents at once.
    I wanted to see if I could do the create the pdf from text file with specific layout in Adobe Acrobat without having to go to Control Panel to preset the Adobe PDF to specific layout at every time.   I would have to set Adobe PDF back to normal layout after I'm done with these pdf print outs.  I do lots of pdfs in normal layout.  Sometimes I would forget to do that.
    So, How do I do that?

    No such luck.  It would output the contents in letter size even in JIS B3 Page layout at MS word. 
    Is there a script or action where I could set the orientation and page size before creating PDF on these text files?

  • Movie refuses to load variables from text file

    Hi,
    I'm sure you can solve my newbie problem in less than 1
    minute...
    I'm pulling my hair out on a template I bought 2 days ago
    from templatemonster.com
    I am using Flash 8 Pro.
    All I want to do is change an existing textfield that is
    Static to Dynamic and load variables from a text file.
    The Action Script I use to do so comes directly from
    Macromedia documentation (see attached)
    It works fine when I create a brand new movie, but doesn't do
    anything when inserted into the template.
    It doesn't even complain about not finding the text file if I
    rename or delete it!
    Here are the FLA and text file:
    Edit : Link to source file removed
    The textfield I would like to change is in the txt2 symbol.
    Here is how I proceed:
    When I open HEADER.FLA, Flash tells me I'm missing a font,
    ok, so I click on Use Default, I'll deal with this later.
    I open up the Movie Explorer, go to Layer 30, go to Frame 75
    and click once on txt2
    I name the instance "myMovie_mc" and save (converts from
    Flash MX to Flash 8)
    I double-click on the Movie Clip, select the word
    "Automobile" on the Stage, change from Static to Dynamic and call
    that instance "myText_txt"
    Still in the Movie Clip, I create a new layer I call
    "actions", and in Frame 1 I copy the attached Action Script:
    This script works when I create a new flash file, but it does
    absolutely nothing in this template.
    I know I'm doing something wrong, but I wonder what?
    Many thanks to any helping soul!
    Ferris.

    try this:
    // Load text as variable and assign it to the
    // dynamic text field
    var features_lv:LoadVars = new LoadVars();
    features_lv.onLoad = onText();
    features_lv.load("safetyFeatures.txt");
    function onText(success:Boolean) {
    if (success) {
    myText_txt.text = features_lv.safetyfeatures;
    } else {
    myText_txt.text = "unable to load text file.";
    or this
    // Load text as variable and assign it to the
    // dynamic text field
    var features_lv:LoadVars = new LoadVars();
    features_lv.onLoad = function(success) {
    if (success) {
    myText_txt.text = features_lv.safetyfeatures;
    } else {
    myText_txt.text = "unable to load text file.";
    features_lv.load("safetyFeatures.txt");

  • Align Columns?  using Acrobat Pro 9 to create pdf from text file(s)

    Hello,
    Every time that I have tried to create a PDF from a text file, the columns dont align.  The default Notepad setting I use to view a text file is Courier New which shows the columns aligned.  How can I set defaults in Acrobat Pro 9 to have columns align?
    Thanks

    By definition a plain text file has no font, so it cannot be monospaced. Acrobat converts plain text using Times, this cannot be changed.
    As TSN suggests to create a PDF from a text file with a specific choice of font and formatting you must print from another application.

  • Brilliant way to create titles from text files

    It was just pointed out to me by a fellow named Greg Hester that there is a way to create titles from a Microsoft Word file using Adobe InDesign. You can create as many titles as you need, and even change text positions around from title to title. Then you export as a PNG.
    If you need to go back and change a color or a font type or size or whatever, you can do that to all of them at once and then just export again. They will automatically update in Premiere Pro.
    I have never even opened InDesign before, and I was able to follow the instructions in this tutorial without a strain.
    The tutorial doesn't show that you can import a frame capture from the video to help position the text, but you can.
    This is very cool. If you subscribe to the Creative Cloud, then you have access to InDesign.

    Best would be to have this template/style functionality in the title tool itself though
    Agreed.
    Remember, all this InDesign thing does is create images that can be used as titles. My Macro created actual titles.
    What really needs to happen is to have a plugin that creates titles from simple text files like the ones created from Notepad, so no Microsoft program is required. The file could have the text, the font style, and many other parameters, and then it could have the time to place the title on the sequence.
    But in the meantime, this InDesign thing seems to be the best we can do for now. If, however, you want to use a fancy font style and it will all be in English, you can use my macro.

  • Create folders from text file

    can anyone show me how to create directories from a text file.
    each line = 1 folder
    name
    name lastname
    and so on...
    thanks in advance

    Xyne wrote:
    skunktrader wrote:Perhaps your input file has msdos style line terminators ie \r\n
    That's what I'm thinking.
    well it was created in notepad and the list was copied from a Excel sheet, how would i go about removing that?

  • Create PDF from text file.

    The CreatePDF app description states "Convert all your Office, Photoshop, ..., Text, and RTF files to PDF using 'Open In' to send the files to the CreatePDF application" (bolding mine).  But I see no way in the iPhone Notes app to do an 'Open In'.  Really?!? I can't even create a PDF from the standard Notes app?!?

    Hello tomscheifler,
    notes in the notes-app are NOTES not FILES.
    Conclusion: You cannot convert them.
    You have take a detour via e.g. "docs to go" and save the note as word doc.
    Then adobe does the job you expect....
    Regards

  • Create Picture from Text File

    I have an 8(column)x20(row) array of bolean data. I want to display this as a black and white picture. I.e have a grid of 8x20 squares which are black if "1" and white if "0" can anyone help?
    Thanks
    Solved!
    Go to Solution.

    Very pretty vi t06afre!
    But there is a better way to enlarge the pixels:
    Message Edited by Thoric on 04-23-2009 03:13 PM
    Thoric (CLA, CLED, CTD and LabVIEW Champion)
    Attachments:
    bandwzoomed.png ‏3 KB

  • Create a Blank Text file if it does not exist in a Given Directory

    Hi,
    I would like to check if text file in a given folder exists or not if not then create a blank text file in a given directory. I was checking File system task, it has options to create directory and move files, copy files but not creating files.
    How can I create a blank text file in a given directory in SSIS using script task or any other way.
    Many thanks.
    Mustafa
    MH

    Thanks Saravana for your help. I am using the following code in the script Task two
    Imports System
    Imports System.Data
    Imports System.Math
    Imports Microsoft.SqlServer.Dts.Runtime
    Imports System.IO
    Imports System.Object
    Imports System.Security.Cryptography
    Imports System.IO.Compression
    <System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
    <System.CLSCompliantAttribute(False)> _
    Partial Public Class ScriptMain
    Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    Enum ScriptResults
    Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
    Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    End Enum
    ' The execution engine calls this method when the task executes.
    ' To access the object model, use the Dts property. Connections, variables, events,
    ' and logging features are available as members of the Dts property as shown in the following examples.
    ' To reference a variable, call Dts.Variables("MyCaseSensitiveVariableName").Value
    ' To post a log entry, call Dts.Log("This is my log text", 999, Nothing)
    ' To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, True)
    ' To use the connections collection use something like the following:
    ' ConnectionManager cm = Dts.Connections.Add("OLEDB")
    ' cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;"
    ' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
    ' To open Help, press F1.
    Public Sub Main()
    ' Add your code here
    Dim inputFile As String
    Dim outputFile As String
    Dim encoding As String
    Dim PrivateKeyInXML As String
    inputFile = Dts.Variables("Item1Path").Value.ToString()
    outputFile = Dts.Variables("OutputFile1").Value.ToString()
    encoding = Dts.Variables("Encoding").Value.ToString()
    PrivateKeyInXML = Dts.Variables("PrivateKey").Value.ToString()
    Dim CallCryptoReader As CryptoReader = New CryptoReader(inputFile, outputFile, encoding, PrivateKeyInXML)
    Dts.TaskResult = ScriptResults.Success
    End Sub
    Public Class CryptoReader
    Private _FileStream As FileStream
    Private _CryptoStream As CryptoStream
    Private _ZipStream As GZipStream
    Private _RSAPrivateKeyinXML As String
    Dim _CryptoAgent As New System.Security.Cryptography.AesCryptoServiceProvider
    'System.Text.Encoding
    Sub New(ByVal inputFile As String, ByVal outputFile As String, ByVal encoding As String, ByVal PrivateKeyInXML As String)
    _RSAPrivateKeyinXML = PrivateKeyInXML
    'Create the crypto agent
    _CryptoAgent = AesCryptoServiceProvider.Create
    '''''''_CryptoAgent.GenerateIV()
    '''''''_CryptoAgent.GenerateKey()
    'Open cypher text for reading in
    _FileStream = New FileStream(inputFile, FileMode.Open)
    ReadHeaderFromFile() 'write out aes key to header
    'Create the stream to decrypt the AES part of the file
    _CryptoStream = New CryptoStream(_FileStream, _CryptoAgent.CreateDecryptor, CryptoStreamMode.Read)
    _ZipStream = New GZipStream(_CryptoStream, CompressionMode.Decompress)
    'setup complete - run decrypt to unprotect the rest of the file
    DecryptFile(outputFile)
    Flush()
    Close()
    Dispose()
    End Sub
    Public Sub Close()
    _CryptoStream.Close()
    _ZipStream.Close()
    _FileStream.Close()
    End Sub
    Public Sub Dispose()
    _CryptoStream.Dispose()
    _ZipStream.Dispose()
    _FileStream.Dispose()
    End Sub
    Public Sub Flush()
    _CryptoStream.Flush()
    _ZipStream.Flush()
    _FileStream.Flush()
    End Sub
    Private Sub ReadHeaderFromFile()
    'Read the AES Key (Protected by RSA Key) and then the IV
    Dim UnProtectedAESKey() As Byte
    Dim buffer(_CryptoAgent.BlockSize - 1) As Byte
    'Read in protected AES Key
    _FileStream.Read(buffer, 0, _CryptoAgent.BlockSize)
    'Decrypt AES Key
    UnProtectedAESKey = releaseKeyFromRSA(buffer)
    _CryptoAgent.Key = UnProtectedAESKey
    ReDim buffer(_CryptoAgent.IV.Length - 1)
    'get IV
    _FileStream.Read(buffer, 0, _CryptoAgent.IV.Length)
    _CryptoAgent.IV = buffer
    End Sub
    Public Sub DecryptFile(ByVal outFilePath As String)
    Dim outFile As New FileStream(outFilePath, FileMode.Create)
    Dim count As Integer = 1024
    Dim buffer(count - 1) As Byte
    Do Until count = 0
    count = _ZipStream.Read(buffer, 0, count)
    outFile.Write(buffer, 0, count)
    Loop
    outFile.Flush()
    outFile.Close()
    outFile.Dispose()
    End Sub
    Private Function releaseKeyFromRSA(ByVal key() As Byte) As Byte()
    Debug.Print("Protected AES Key - " & key.ToString)
    Dim cspParam As New CspParameters()
    Dim RSA As New RSACryptoServiceProvider(1024, cspParam)
    'private
    RSA.FromXmlString(_RSAPrivateKeyinXML)
    Dim decryptedAsByte() As Byte = RSA.Decrypt(key, True)
    Debug.Print("Release RSA - " & System.Text.Encoding.ASCII.GetString(decryptedAsByte))
    Return decryptedAsByte
    End Function
    End Class
    End Class
    I am using the Outputfile1 variable. this is the variable where the path of the file will come which was created in the previous script task. In this task i got the exception that it is alread in use.
    MH

  • How to open saved files using 'read from text file' function

    Hi everyone, I am having a hard time trying to solve the this particular problem ( probably because I am a newb to lanbview ). Anyway , I am able to save the acquired waveforms by using the 'Write to text file' icon. I did manually modify the block diagram of the 'Write to text file' icon and create the correct number of connector so as to make my program work. But now I have no idea on how to modify the block diagram of the 'Read from text file' block diagram to make my program 'open' my saved waveforms. Or i do not have to modify anything from the block diagram of the 'Read from text file'? Can anyone teach/help me connect up? Do i need the build array on the "open" page?
    Here are some screenshots on part of my program  
    let me know if you guys would need more information / screenshots thank you!
    Attachments:
    ss_save.jpg ‏94 KB
    ss_open.jpg ‏94 KB
    modified_writetotextfile.jpg ‏99 KB

    Ohmy, thanks altenbach. oh yeah i forgot about those sub VIs. will upload them now. Was rather demoralized after reading the comments and really struck me on how weak i'm at on labview really hope to get this done. But of course i have to study through and see how it works. Actually i am going to replace those 'signal generators sub vi' with ThoughtTechonology's sample code so i can obtain data waveforms real-time using Electrocardiography (ECG) ,Electromyography (EMG ) and Electroencephalography (EEG) hopefully i can find out how to connect the sample code.
    ( ps . cant connect it now unless my program is working otherwise labview will crash ) 
    ( p.s.s the encoder of my biofeedback trainer already acts as an DAQ so i wont need to place an DAQ assistant in my block diagram i suppose )
    The sample code of ThoughtTechnology is named as attachment.ashx.vi. too bad i cant use it and present it as my project
    Attachments:
    frequency detactor.vi ‏53 KB
    signal generator.vi ‏13 KB
    attachment.ashx.vi ‏40 KB

  • LabVIEW for ARM 2009 Read from text file bug

    Hello,
    If you use the read from text file vi for reading text files from a sdcard there is a bug when you select the option "read lines"
    you cannot select how many lines you want to read, it always reads the whole file, which cause a memory fault if you read big files!
    I fixed this in the code (but the software doesn't recognize a EOF anymore..) in CCGByteStreamFileSupport.c
    at row 709 the memory is allocated but it tries to allocate to much (since u only want to read lines).
    looking at the codes it looks like it supposed to allocated 256 for a string:
    Boolean bReadEntireLine = (linemode && (cnt == 0)); 
    if(bReadEntireLine && !cnt) {
      cnt = BUFINCR;    //BUFINCR=256
    but cnt is never false since if you select read lines this is the size of the file!
    the variable linemode is also the size of the file.. STRANGE!
    my solution:
    Boolean bReadEntireLine = (linemode && (cnt > 0));  // ==
     if(bReadEntireLine) {    //if(bReadEntireLine && !cnt) {
      cnt = BUFINCR;
    and now the read line option does work, and reads one line until he sees CR or LF or if the count of 256 is done.
    maybe the code is good but the data link of the vi's to the variables may be not, (cnt and linemode are the size of the file!)
    count should be the number of lines, like chars in char mode.
    linemode should be 0 or 1.
    Hope someone can fix this in the new version!
    greets,
    Wouter
    Wouter.
    "LabVIEW for ARM guru and bug destroyer"

    I have another solution, the EOF works with this one.
    the cnt is the bytes that are not read yet, so the first time it tries to read (and allocate 4 MB).
    you only want to say that if it's in line mode and cnt > 256 (BUFINCR) cnt = BUFINCR
    the next time cnt is the value of the bytes that are not read yet, so the old value minus the line (until CR LF) or if cnt (256) is reached.
    with this solution the program does not try to allocate the whole file but for the max of 256.
    in CCGByteStreamFileSupprt.c row 705
     if(linemode && (cnt>BUFINCR)){
       cnt = BUFINCR;
    don't use the count input when using the vi in line mode. count does not make sense, cnt will be the total file size. also the output will be an array.
    linemode seems to be the value of the file size but I checked this and it is just 0 or 1, so this is good
    update: damn it doesn't work!
    Wouter.
    "LabVIEW for ARM guru and bug destroyer"

  • How to load date and time from text file to oracle table through sqlloader

    hi friends
    i need you to show me what i miss to load date and time from text file to oracle table through sqlloader
    this is my data in this path (c:\external\my_data.txt)
    7369,SMITH,17-NOV-81,09:14:04,CLERK,20
    7499,ALLEN,01-MAY-81,17:06:08,SALESMAN,30
    7521,WARD,09-JUN-81,17:06:30,SALESMAN,30
    7566,JONES,02-APR-81,09:24:10,MANAGER,20
    7654,MARTIN,28-SEP-81,17:24:10,SALESMAN,30my table in database emp2
    create table emp2 (empno number,
                      ename varchar2(20),
                      hiredate date,
                      etime date,
                      ejob varchar2(20),
                      deptno number);the control file code in this path (c:\external\ctrl.ctl)
    load data
    infile 'C:\external\my_data.txt'
    into table emp2
    fields terminated by ','
    (empno, ename, hiredate, etime, ejob, deptno)this is the error :
    C:\>sqlldr scott/tiger control=C:\external\ctrl.ctl
    SQL*Loader: Release 10.2.0.1.0 - Production on Mon May 31 09:45:10 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Commit point reached - logical record count 5
    C:\>any help i greatly appreciated
    thanks
    Edited by: user10947262 on May 31, 2010 9:47 AM

    load data
    infile 'C:\external\my_data.txt'
    into table emp2
    fields terminated by ','
    (empno, ename, hiredate, etime, ejob, deptno)Try
    load data
    infile 'C:\external\my_data.txt'
    into table emp2
    fields terminated by ','
    (empno, ename, hiredate, etime "to_date(:etime,'hh24:mi:ss')", ejob, deptno)
    this is the error :
    C:\>sqlldr scott/tiger control=C:\external\ctrl.ctl
    SQL*Loader: Release 10.2.0.1.0 - Production on Mon May 31 09:45:10 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Commit point reached - logical record count 5
    C:\>
    That's not an error, you can see errors within log and bad files.

  • "Import from Text File" & "Upload from Clipboard" icon not appearng in F110

    Hi Experts,
    While making the payment to the vendors through TN F110, in "PARAMETER" screen just next to 'STATUS' screen, there is a vendor field for selection in range and just ahead of this there is an icon for multiple vendor selection ( Bold arrow mark ). If I click on that multiple vender selection icon ( on bold arrow mark ), an another screen opens for multiple selection for vendors. In this screen 'Enter, Copy, Delete etc' icons are appearing at the bottom of the screen but "Import from Text File" & "Upload from Clipboard" icon are not appearing there.
    Can you please let me know how to bring that icons there?
    Points would be awarded.
    Rgds,
    Shailesh

    Hi Ravi,
    I have not yet created anything and have just entered the parameter. In the multiple screen for vendors there are 5 fields for individual and 5 for range selection. Even you can put more than five range selections or individual selections by clicking on the page button but there I am not finding these two icons.
    Can you please check at your end and let me know if you are getting or what to do to bring those two icons in F110.
    Rgds,
    Shailesh

  • How to create and read text file using LabVIEW 7.1 PDA module?

    How to create and read text file using LabVIEW 7.1 PDA module? I can not create a text file and read it.
    I attach my code here.
    Attachments:
    File_IO.vi ‏82 KB

    Well my acquisition code runs perfect. The problem is reading it. I can't seem to read my data no matter what I do. My data gets saved as a string using the array to string vi but I've read that the string to array vi (which I need to convert back to array to read my data) does not work on the pda. I'm using version 8.0. So I was trying to modify the program posted in this discussion so that it would save data from my DAQ. I did that but I still can't read the data after its saved. I really don't know what else to do. All I need to do is read the data on the pda itself. I can't understand why I'm having such a hard time doing that. I found a possible solution on another discussion that talks about parsing the strings because of the bug in the "string to array" vi. However, that lead me to another problem because for some reason, the array indicators or graphs don't function on the pda. When i build the program to the pda or emulator, the array indicators are faded out on the front panel as if the function is not valid. Does this kind of help give a better picture of what I'm trying to do. Simply read data back. Thanks.

  • CO-PA load data from text file

    Hello
    At present, in our company, we load data from Excel files to CO-PA. Is there any way to load those data to CO-PA from text files ?
    I will be grateful for any suggestions.

    You can create a structure using KEFA, assign the Value fields in KEFB and then use KEFC to upload data against that structure.
    You have various file format options, but I don't think Excel is one of them... you have have to save the file as txt and upload.
    Play around with those transactions and come back if you need additional help.
    Cheers.

Maybe you are looking for

  • How to update ADF VO object to refresh the data in ADF Pivot table

    I need to know how to update the View object so that the date in pivot table is refreshed/updated/filtered. here are the steps I performed to create ADF pivot table application using VO at design time. 1) created a collection in a Data Control (ViewO

  • How to use ENQUE and DEQUE BAPI in Visual Composer

    Hi All,        We are planning to update employee Address through Portal for that one we did one BAPI which supports ADDRESS Change of an employye, through Visual Composer we developed the application and we integrated into SAP Portal but we are not

  • Trouble installing Boot Camp and Windows 8

    I'm attempting to install Boot Camp for the first time using OS X 10.10.1 / Boot Camp 5.1.2. When I conduct the install, I get a message stating that this machine (Macbook Air, Late 2010) can only install Windows 7. Apple's Documentation states the f

  • I want to backup a user in increasement mode

    I know oralce supports increasement backup for entire database(all objects). but I want to backup a user in such mode. who can tell me how to do? thanks.

  • Sizing a standby system for Maximum Availability

    - Having primary and secondary sites with the SAME database server configuration. The server configuration will either be a SMP system with lots of processors or a RAC consisting of a number of 4-way SMP processors. - Data Guard shall be used for the