none
Powershell to import a computer list and remove an icon RRS feed

  • Question

  • I need to import a list of domain PCs. For each entry, I have to remove a .lnk file from Public Desktop (Win7) and write the results to a .log
    Friday, June 20, 2014 4:03 PM

Answers

  • Get-Content C:\Data\PS\Imports\Import.csv | 
          ForEach-Object{
               Get-Item "\\$($_.Name)\c$\users\Public\Desktop\Series *.lnk" -EA 0 |
                          Remove-Item -WhatIf
    } 


    ¯\_(ツ)_/¯

    • Marked as answer by Native.Son Saturday, June 21, 2014 1:49 PM
    Friday, June 20, 2014 7:57 PM

All replies

  • I don't see a question.

    What have you tried so far, and with what results?


    -- Bill Stewart [Bill_Stewart]

    Friday, June 20, 2014 4:04 PM
    Moderator
  • Here is a starter:

    Get-AdComputer |
         %{
              Get-Item "
    \\$($_.Name)\c$\users\Public\Desktop\mylink.lnk" -EA 0 |
                     Remove-Item -WhatIf
         }


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, June 20, 2014 4:18 PM
    Friday, June 20, 2014 4:17 PM
  • I guess I drifted off for a second. The question is how would I get started putting something together to do that as a novice?

    I can do it through batch, but just looking to learn it in PS

    Friday, June 20, 2014 4:36 PM
  • Here is what I currently have:

    $Computers = Get-Content "C:\Data\PS\Imports\Import.csv" |
    %{Get-Item "\\$Computers($_.Name)\c$\users\Public\Desktop\Series *.lnk" -EA 0 |
     Remove-Item -WhatIf} |
    Export-csv -Path "C:\Data\PS\Exports\Results.csv"

    and here is what I get:

    Get-Item : Cannot retrieve the dynamic parameters for the cmdlet. The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. Since I cant shorten the path, what are some other options?

    Friday, June 20, 2014 5:23 PM
  • Get-Content C:\Data\PS\Imports\Import.csv | 
          ForEach-Object{
               Get-Item "\\$($_.Name)\c$\users\Public\Desktop\Series *.lnk" -EA 0 |
                          Remove-Item -WhatIf
    } 


    ¯\_(ツ)_/¯

    • Marked as answer by Native.Son Saturday, June 21, 2014 1:49 PM
    Friday, June 20, 2014 7:57 PM
  • Thanks JRV
    Saturday, June 21, 2014 1:49 PM