Windows PowerShell: List items in "Desktop" or "Documents"
Windows PowerShell
Get a list of items in "Desktop" or "Documents"
- Creating a function.
function testFunc($inarg){
cd ~
if($inarg -eq "Desktop"){cd "Desktop";}
elseif($inarg -eq "Documents"){cd "Documents";}
$items= ls;
return $items;
}
- Command line to print(echo) items(files and folders) in "Desktop".
$items=Invoke-Command -ScriptBlock $function:testFunc -ArgumentList "Desktop";echo $items;
- Command line to print(echo) items(files and folders) in "Documents".
$items2=Invoke-Command -ScriptBlock $function:testFunc -ArgumentList "Documents";echo $items2;

Comments
Post a Comment