Sunday 15 August 2010

powershell - How to use output of get-childitem command -



powershell - How to use output of get-childitem command -

i wanted zip out set of

get-childitem -path e:\test | where-object {$_.psiscontainer} | sort-object lastwritetime -descending | select-object -first 1

i have tried this

$command ='get-childitem -path e:\test | where-object {$_.psiscontainer} | sort-object lastwritetime -descending | select-object -first 1'; $file= iex $command

and set $file in zip function resulted error .

get-childitem : access path 'c:\windows\system32\com\dmp' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\com\dmp:string) [get-childitem], unauthorizedaccessexception + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\config' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\config:string) [get-childitem], unauthorizedaccessexception + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\configuration' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\configuration:string) [get-childitem], unauthorizedaccessexcept ion + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\ias' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\ias:string) [get-childitem], unauthorizedaccessexception + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\inetsrv\config' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\inetsrv\config:string) [get-childitem], unauthorizedaccessexcep tion + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\logfiles\fax\incoming' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\syst...es\fax\incoming:string) [get-childitem], unauthorizedaccessexcept ion + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\logfiles\fax\outgoing' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\syst...es\fax\outgoing:string) [get-childitem], unauthorizedaccessexcept ion + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\logfiles\firewall' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\logfiles\firewall:string) [get-childitem], unauthorizedaccessex ception + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\logfiles\httperr' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\logfiles\httperr:string) [get-childitem], unauthorizedaccessexc eption + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\logfiles\wmi' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\logfiles\wmi:string) [get-childitem], unauthorizedaccessexcepti on + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\msdtc' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\msdtc:string) [get-childitem], unauthorizedaccessexception + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\networklist' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\networklist:string) [get-childitem], unauthorizedaccessexceptio n + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\spool\printers' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\spool\printers:string) [get-childitem], unauthorizedaccessexcep tion + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\spool\servers' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\spool\servers:string) [get-childitem], unauthorizedaccessexcept ion + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\sru' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\sru:string) [get-childitem], unauthorizedaccessexception + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\tasks' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\tasks:string) [get-childitem], unauthorizedaccessexception + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\wbem\mof' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\wbem\mof:string) [get-childitem], unauthorizedaccessexception + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\wdi' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\wdi:string) [get-childitem], unauthorizedaccessexception + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand get-childitem : access path 'c:\windows\system32\wfp' denied. @ e:\scripts\last modified folder.ps1:15 char:8 + $bak = get-childitem -recurse -path $filepath #| where-object { $_.extension -eq ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (c:\windows\system32\wfp:string) [get-childitem], unauthorizedaccessexception + fullyqualifiederrorid : dirunauthorizedaccesserror,microsoft.powershell.commands.getchilditemcommand

there missing code. stands contains no info zipping directory. root of issue code showing asking invoke-expression run folder name. $command returning object contains 1 folder. wanted?

you take folder object , set invoke-expression. $file = means mean set results of invoke-expression $file. notice have command in single quotes mean invoke-expression effort expand it. more testing required. take guess want alter little.

$folder = get-childitem -path e:\test | where-object {$_.psiscontainer} | sort-object lastwritetime -descending | select-object -first 1 -expandproperty fullname

that @ to the lowest degree homecoming total folder path looking for. trying i'm lost on. if have @ to the lowest degree dotnet 4.5 zip illustration so question

$folder = get-childitem -path e:\test | where-object {$_.psiscontainer} | sort-object lastwritetime -descending | select-object -first 1 -expandproperty fullname $destination = "e:\test\myzip.zip" [reflection.assembly]::loadwithpartialname( "system.io.compression.filesystem" ) [system.io.compression.zipfile]::createfromdirectory($folder, $destination)

with powershell community extensions find cmdlet called write-zip use

get-childitem -path e:\test | where-object {$_.psiscontainer} | sort-object lastwritetime -descending | select-object -first 1 | write-zip -includeemptydirectories -outputpath e:\test\myzip.zip

if prefer: here solution uses functionality builtin powershell creating zipped/compressed folder in windows using powershell or command line

powershell get-childitem

No comments:

Post a Comment