Script Help - Working with Files - Reading/Writing

Hey Folks,
I need help build a script that will read a text string from a specific .INI file, and then write that string to a file along with the name of the computer where the string originated from.
I plan on deploying this script to our targeted workstations with SCCM 12, so it does not need recursive abilities. We want each of the machines which run the script to write their data to a single file with a date stamp as part of the name. The data written
needs to include the unique string which follows this format "devicename=DJ########", along with the computer's name. The device name which needs to be extracted starts with DJ and is followed by an 8 digit number. It would be better if we could
use export-csv than out-file. 
This is what my very inexperienced self came up with so far:
get-content 'C:\users\Public\Something\myfile.ini' | Select-String devicename=dj | out-file
\\server\folder\data.txt -append
I
found this bit of code which should allow me to set the file name to a date, but I am unsure exactly how to implement this:
$enddate = (Get-Date).tostring("yyyyMMdd")
$filename = 'C:\Documents and Settings\User\Desktop\' + $enddate + '_VMReport.doc'
$filename
The developer of a core piece of software requires all computers have a unique ID, but provides absolutely no tools or guidance for tracking this crucial information. Any input you can provide will be greatly appreciated!
Please help us fix this nightmare! Thank you in advance!

I am trying to add a step where the script grabs a list of all domain workstations and saves it to a file. This file is then used as the input for the rest of the script. There is a problem with the way the computers names are imported using this method.
Here is the script:
# Rename the existing DJNumbers.csv to yesterday's date
$date = (Get-Date).AddDays(-1)
Rename-Item -Path '\\Server\Library\DJs\DJnumbers.csv' -NewName ("DJNumbers_{0}.csv" -f (Get-Date $date -Format yyyy-MM-dd))
#Save a list of all current AD computers
Get-ADComputer -Filter * | select name | Out-File \\Server\C$\DJs\complist.csv
#Extract the DJ number for every computer in complist.csv
Get-Content '\\Server\C$\DJs\complist.csv' |
ForEach-Object {
$devicename=get-content "\\$_\C$\Users\Public\myfile.ini" | Select-String devicename=
$djnumber=$devicename -replace "devicename=","`t"
$prize=$_ += $djnumber
$prize | Out-File \\Server\Library\DJs\DJnumbers.csv -Append
The problem is that the computer names include a ton of blank spaces if I use Out-File in the line:
#Save a list of all current AD computers
Get-ADComputer -Filter * | select name | Out-File \\Server\C$\DJs\complist.csv
Error looks like this:
get-content : Cannot find path '\\CM112233
\C$\Users\Public\Software\myfile.ini' because it does
not exist.
At line:11 char:13
+ $devicename=get-content "\\$_\C$\Users\Public\Software\...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (\\CM112233 ...ction\myfile.ini:String) [Get-Content], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
If I use Export-Csv, it puts ""'s around the computer names and that breaks it as well.
#Save a list of all current AD computers
Get-ADComputer -Filter * | select name | Export-Csv \\Server\C$\DJs\complist.csv
This is the error:
get-content : Illegal characters in path.
At line:11 char:13
+ $devicename=get-content "\\$_\C$\Users\Public\Software\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (\\"CM112233"\C$\U...are\myfile.ini:String) [Get-Content], ArgumentException
+ FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.GetContentCommand

Similar Messages

  • Help working with File() objects

    Hi,i'm sorry for my not-so-perfect English.
    I'm working with java.io.File object, to use and know the contents of a folder.
    But if i try to use the function list() on a folder that is the first in my hard drive (For example: C:\Test on windows, or /usr on unix), and try to get the Parent...i receive null.
    This is a regoular way,in my opinion; But i have a problem: i'm working at a Java File Manager, and i'd like to LIST all my hard driver present in my computer (ie. C:,D:, E:) but i don't really know how to do...!!
    On UNIX, i can resolve this problem using a list() on /mnt folder, for mounted drive...but on Windows...how can i!?
    Thanks for the answers...

    Hi,
    Take a look at:
    File.listRoots()
    Kaj

  • Will file converting pdf file to excel work with Adobe Reader 10.1, Windows 7 platform?

    Will file converting pdf file to excel work with Adobe Reader 10.1, Windows 7 platform?  It shows that it is available for purchase but does it perform?  Will this work only with Reader XI?  Is the conversion done on-line?

    Moved to Adobe ExportPDF.
    The file is uploaded to the web for conversion. You can manually upload pdfs for conversion with your web browser and/or with Reader 10.1.

  • Help: Working with .MOV files in FCP and forced to RENDER FOR EVERY EDIT

    I'm working with .MOV files from my digital camera in Final Cut Pro and every time I make a new edit, I have to render it in order to see it in the canvas.
    How do I make it so that I don't have to render every edit in order to see it?
    (I've worked with files straight from a DV camera, and editing went fine. I'm assuming it has to do with the .MOV files)

    DV Cameras are not the same thing as a Digital camera. Digital cameras offer video on a limited basis and it's usually highly compressed in a non-editing format such as MPEG-2 or similar. NLEs are made to work with video cameras, not still cameras which is why you're having trouble.
    That's not to say you can't edit video captured with a digital camera, but you need to know how to prep it for editing. Some digital cameras shoot at odd frame rates and they all use some form of compression that is not typically used in editing. This means that you'll likely need to convert your clips to an editable format first using Compressor.
    Andy

  • Work with Files in Java

    Hello!
    Can anyone help me. How can I API in Java Technology for files to find ?

    don't uite understand your question.
    here's the location of java API for File class, for working with File and Directory..
    http://java.sun.com/j2se/1.3/docs/api/java/io/File.html
    for reading and writing..you may want to look at th eio package for classes such as
    Reader, FileReader, BufferedReader, Writer, FileWriter, BufferedWriter
    here's java API
    http://java.sun.com/j2se/1.4.2/docs/api/

  • How to work with files in folders on Application/Presentation Server

    Hi,
    I am working on interface program in which files are populated in folders in application/presentation server in the format 'ABCsy-datumsy-uzeit.txt'(e.g.ABC20051022161450.txt,ABC20051022161455.txt ) in directory c:\temp.
    I want to sort all these files and read in sorted manner.
    can anybody help me out in this.
    waiting for reply.
    thanks & regards,
    Nitin

    Hi,
      This logic will work for files on presentation server,
    DATA:  l_count TYPE i,
           l_filename TYPE string,
           t_files TYPE string OCCURS 0 WITH HEADER LINE,
           BEGIN OF t_files_sorted OCCURS 0,
             file_prefix(3),
             file_date LIKE sy-datum,
             file_time LIKE sy-uzeit,
             file_extension(4),
           END OF t_files_sorted,
           t_text TYPE TABLE OF w3html.
    CALL METHOD cl_gui_frontend_services=>directory_list_files
      EXPORTING
        directory                   = 'C:\Temp'
        FILTER                      = '*.txt'
         files_only                  = 'X'
       DIRECTORIES_ONLY            =
      CHANGING
        file_table                  = t_files[]
        count                       = l_count
      EXCEPTIONS
        cntl_error                  = 1
        directory_list_files_failed = 2
        wrong_parameter             = 3
        error_no_gui                = 4
        OTHERS                      = 5.
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP AT t_files.
      t_files_sorted = t_files.
      APPEND t_files_sorted.
    ENDLOOP.
    SORT t_files_sorted BY file_date file_time.
    LOOP AT t_files_sorted.
      CONCATENATE 'C:\Temp\' t_files_sorted INTO l_filename.
      CALL METHOD cl_gui_frontend_services=>gui_upload
        EXPORTING
          filename                = l_filename
         FILETYPE                = 'ASC'
         HAS_FIELD_SEPARATOR     = SPACE
         HEADER_LENGTH           = 0
       IMPORTING
         FILELENGTH              =
         HEADER                  =
        changing
          data_tab                = t_text[]
        EXCEPTIONS
          FILE_OPEN_ERROR         = 1
          FILE_READ_ERROR         = 2
          NO_BATCH                = 3
          GUI_REFUSE_FILETRANSFER = 4
          INVALID_TYPE            = 5
          NO_AUTHORITY            = 6
          UNKNOWN_ERROR           = 7
          BAD_DATA_FORMAT         = 8
          HEADER_NOT_ALLOWED      = 9
          SEPARATOR_NOT_ALLOWED   = 10
          HEADER_TOO_LONG         = 11
          UNKNOWN_DP_ERROR        = 12
          ACCESS_DENIED           = 13
          DP_OUT_OF_MEMORY        = 14
          DISK_FULL               = 15
          DP_TIMEOUT              = 16
          others                  = 17.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    *****Your processing here..
    ENDLOOP.
    Also, use the FM that MAX has if you have to work with files on application server by replacing code in the above logic at appropriate places, like replace
    cl_gui_frontend_services=>directory_list_files
    with the corresponding fm
    and replace cl_gui_frontend_services=>gui_upload
    with OPEN DATASET...
         CLOSE DATASET...
    logic.
    Hope this helps..
    Sri
    Message was edited by: Srikanth Pinnamaneni

  • Cannot print "working with files and folders htm

    When I try to print "Working with files-and-folders" from a Google search, it only prints part of it. I have changed my destination folder to no avail. Thank you or any help, Jack Menendez

    What's the best method for moving all my nonsystem related stuff over to this new driveIan has provided you with the best solution, SuperDuper.
    But if you have a 250 GB external, you really ought to clone your entire system,(only about 3 GB) so you have a backup.
    I keep mine with a complete clone of my internal, that way it is easy to boot from the external and run utilities like Disk Utility, TechToolPro, DiskWarrior, etc. on the internal and vice versa.
    If you run into a problem with say Preferences and don't know which one is the troublemaker, just trash the whole pref folder and use the good one from the clone. Font problem, same deal. And, if diaster ever strikes, you can just boot up from your external and keep right on working - fix the internal when you have time.
    That's my 2 cents anyway
    -mj
    [email protected]

  • [svn:osmf:] 13494: Update build script to work with Flex 4 SDK.

    Revision: 13494
    Revision: 13494
    Author:   [email protected]
    Date:     2010-01-13 20:30:13 -0800 (Wed, 13 Jan 2010)
    Log Message:
    Update build script to work with Flex 4 SDK.
    Modified Paths:
        osmf/branches/flex4/build/build.xml

    No, you don't need Flash Builder to use the Flex SDK. If you download the SDK and unzip it, you'll find a 'bin' directory that has the mxmlc compiler in it. You can compile Actionscript or MXML files using that.
    ./mxmlc MyFlexApp.mxml
    If you are building an AIR application, you will use amxmlc
    ./amxmlc MyAIRFlexApp.mxml
    Then, launch your AIR application using adl
    ./adl.exe MyAIRFlexApp-app.xml
    Hope this helps,
    Joan

  • Freeze up after working with files copied to DVD. A105-4274 Satillite

    When working with files copied to a DVD, when ejecting my computer locks up. Have to turn it off manually and restart. 
    Can use anyother type of DVD, and this does not happen. Only useing DVD with files written to it. This only happens when i work with the files and then eject the DVD. Please I need help
    Solved!
    Go to Solution.

    ebonykaneezer wrote:
    When working with files copied to a DVD, when ejecting my computer locks up. Have to turn it off manually and restart. 
    Can use anyother type of DVD, and this does not happen. Only useing DVD with files written to it. This only happens when i work with the files and then eject the DVD. Please I need help
    I'm guessing that you are just pressing the eject button on the drive.  Don't do that.
    Quit the application that you are using to work with the files.  Then open Windows Explorer, right-click the CD/DVD drive and click on 'Eject'.

  • I worked with files in LR that were originally on my C drive, then were moved to an external HD for storage. I now want to do some more work on those files (which have the same file name as on the C drive). I plugged the drive into my computer and it show

    I worked with files in LR that were originally on my C drive, then were moved to an external HD for storage. I now want to do some more work on those files (which have the same file name as on the C drive). I plugged the drive into my computer and it shows in LR under folders as the F drive and the little green light is on, but LR is showing only the first 6 files and not the remaining 200 or so. How do I expand the F folder to expose all files?

    I worked with files in LR that were originally on my C drive, then were moved to an external HD for storage. I now want to do some more work on those files (which have the same file name as on the C drive). I plugged the drive into my computer and it shows in LR under folders as the F drive and the little green light is on, but LR is showing only the first 6 files and not the remaining 200 or so. How do I expand the F folder to expose all files?

  • PDF Portfolio does not work with iOS Reader 11.3.2 on iOS 7.1.2

    Well this is upsetting. I created a PDF form with several pages of the same form (it's a travel log).
    My hoping to use Adobe Reader to complete the form and save back as a week at a time won't work.
    I created the form using Acrobat Pro 9 from CS5.
    Does anyone know if a PDF form in a Portfolio should work with Adobe Reader on the iPad2/
    Also, what can I use that works with forms as a portfolio?
    Ken

    Ken,
    please could you describe your workflow. It might help to find some solution. Also it would be great if you can share a sample of your document. Please email it to [email protected] with the reference to this discussion "PDF Portfolio does not work with iOS Reader 11.3.2 on iOS 7.1.2"
    thank you.

  • Adobe Form Calling WebService Doesnu00B4t work with Adobe Reader 7

    Hi experts,
    We have created and adobe form that simulates a PM Notification in which the user, without logging into SAP, through an RFC and WebServices can create the notification into SAP.
    This process only works with Adobe Reader 9 and not with Adobe Reader 7.
    Can anyone tell me what main difference/component/functionality does Adobe Reader 9 have that Adobe Reader 7 doesn´t?
    When I call the Webservice through the form in Adobe 7, a pop-up message appears that says:
    "Error attempting to read from file.
    http://desaecc6.codelco.cl:8001/sap/bc/rfc/sap/zi_aviso_adobe_pm12/222/zi_aviso_adobe_pm12/zi_aviso_adobe_pm12"
    Any ideas why this error ocurrs only in Adobe Reader 7?
    Thanks and best regards,
    Fernando Montenegro

    Hello,
    I cannot tell what are the exact differencies between the version. But I can tell you should always use (at least try to use the newest Reader). I guess you´re not the only developer on Forms, so there are possibly more people depending on the version of the client browser/ Reader. There is a solution for this problem, which does not ask anything from you, only the user.
    You can easily test the Reader version through JS coding and act based on the result. I use this like this "if your Reader is lower than 8.1" then "message popup = We are sorry, your Reader is too old, this form won´t work for you. Please upgrade first.". It takes like 5 minutes (10 for lame users at max) to update his Reader.
    Maybe you should this about such a test, if the user passes the test, his application won´t have any problem, if not there is no guarantee. And YOU have no problem, nobody tells you "hey sir, your form is not working, I´m not gonna pay you".
    Otto

  • How to work with file system in linux within a JSF app?

    I use this line in my backing bean to log some events:
    FileHandler fhxml = new FileHandler("../webapps/MyWebApp/Log/MyWebAppLog.xml", append);
    fhxml.setFormatter(new XMLFormatter());That works fine in windows but when I deploy it in my Tomcat 6 in linux It doesn't work. How can I work with file system in linux?

    You should never use relative paths to access the filesystem. The path would be relative to the current working directory which is not per se the same in all environments. To convert a relative web path to an absolute file system path, you need ServletContext#getRealPath(). Use this absolute file system path in the java.io stuff. In a JSF application on top of Servlet API you can get the underlying ServletContext by ExternalContext#getContext().
    Alternatively, if the file is located in one of the default paths of the classpath or if its path is added to the classpath, you can also just use ExternalContext#getResource() or even #getResourceAsStream() using just the file name.

  • Managing spaces when working with files

    Hi, how can I work with files on windows on paths thats have blank spaces like "Documents and Settings", I used getResource().getFile() and writting the path but it always fails!
    The FileOutputStream always thorws the exception FIleNotFoundException.
    I tried the path with blank spaces and tried with %20 but always is the same.

    Are you saying that OutputStream os = new FileOutputStream("C:/Documents
    and
    Settings/AAD/workspace/MobileServer/bin/Configuracion/
    conexiones.omt");throws an exception? If so, what exception?Exactly it throws an Exception.
    java.io.FileNotFoundException: C:\Documents and Settings\AAD\workspace\MobileServer\bin\server\Configuracion\conexiones.omt (El sistema no puede hallar la ruta especificada)
         at java.io.FileOutputStream.open(Native Method)
         at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
         at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
         at server.tcp.GestionTCP.guardar(GestionTCP.java:118)
         at server.tcp.GestionTCP.mouseReleased(GestionTCP.java:89)
         at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
         at java.awt.Component.processMouseEvent(Component.java:6038)
         at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
         at java.awt.Component.processEvent(Component.java:5803)
         at java.awt.Container.processEvent(Container.java:2058)
         at java.awt.Component.dispatchEventImpl(Component.java:4410)
         at java.awt.Container.dispatchEventImpl(Container.java:2116)
         at java.awt.Component.dispatchEvent(Component.java:4240)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
         at java.awt.Container.dispatchEventImpl(Container.java:2102)
         at java.awt.Window.dispatchEventImpl(Window.java:2429)
         at java.awt.Component.dispatchEvent(Component.java:4240)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
         at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

  • How to get this script to work with different browser

    Do you guys know how to get this script to work with mozilla firefox? 
    do shell script "open -a safari 'https://login.binck.nl/klanten/Login.aspx?ReturnUrl=%2fklanten%2fdefault.aspx'"
    tell application "Safari"
      activate
              tell document 1
                        repeat until ((do JavaScript "location.host") is "login.binck.nl")
                                  delay 1
                        end repeat
      do JavaScript"document.getElementById('ctl00_Content_Gebruikersnaam').value='sim';document.ge tElementById('ctl00_Content_Wachtwoord').value='password';window.open(document. g etElementById('ctl00_Content_LoginButton').href, '_self', 'true');"
              end tell
    end tell
    Thank you so much in advance:)

    That isn't possible. Firefox's AppleScript dictionary doesn't contain anything which can be used to manage JavaScripts.
    (63741)

Maybe you are looking for

  • App store browser on iPad loses it's place

    While browsing the app store, after viewing an app's detail, the browser frequently starts over at the 1st screen of apps in the category - rather than where I was previously browsing. This is very frustrating - especially in a category of thousands

  • Work flow - reg

    Hi all, Can anybody plz send links / document of work flow. This is little bit urgent. Thanks in advance. Regards, Dheeraj

  • Validate RMAN backupset

    Hello, Two nodes RAC system. Database version 11gR2 I have two scripts - one script backups a database to ASM FRA (local backup) and other script use the command "backup backupset" as shown below to the remote NFS mount. run { allocate channel d2 dev

  • Returning Return in PowerShell

    Hey all, I'm trying to write a function in PowerShell where before running the onClick handler it does some basic error checking and if it finds an error to exit the onClickHandler. But it's not returning my return command like I'm used to in LUA. So

  • OMG!!!!!

    I went to apple.com to see what was wrong with my Apple ID and when I went it wouldn't let me in because I couldn't remember the answers to my old security questions!!!!!    And I've gotten myself into a really tough situation can you help me please?