powershell-3.0

Get Active Directory Information from PC's in a text file - Powershell

妖精的绣舞 提交于 2019-12-11 18:12:59
问题 I am running to an issue with a Powershell command line I'm attempting to run. What we are needing is to get the PC Name and LastLogonDate from PC's in a list of text files with Powershell. Here is the code I'm attempting to run: Get-Content C:\Hosts.txt | ForEach-Object{Get-ADComputer $_ -Properties Name,LastLogonDate | Select-Object Name,LastLogonDate | Export-Csv C:\Output.csv} When I run that code I get an error stating: "Cannot find a object with identity: 'ComputerName'" despite the

calling powershell functions through c#

房东的猫 提交于 2019-12-11 17:35:06
问题 I'm trying to call PowerShell function through c# code. **#This is sample PowerShell function** function Add-num { param($int1,$int2) Write-Host ($int1 + $int2) } **#This is my c# code** class Program { static void Main(string[] args) { String file = @"E:\powershell\Untitled3.ps1"; Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); using (PowerShell PowerShellInstance = PowerShell.Create()) { PowerShellInstance.AddScript(file); PowerShellInstance.AddCommand("Add-num")

Regex expression to match forward slash followed by string

给你一囗甜甜゛ 提交于 2019-12-11 16:54:59
问题 I need to filter a string, if it contains three strings: /A/ABC A_ABC Downloaded I have two types of lines. All contain Downloaded , but only either /A/ABC or A_ABC Every substring has spaces to their left and right. What are the correct regex expressions to match a line, if it contains Downloaded and ABC ? My big problem to match for ABC are either the slash or underscore on its left side. I tried the following expression: '\bDownloaded\b + \b/A/ABC\b | \/ABC\b' However I don't receive the

Compare two lists in Powershell

大城市里の小女人 提交于 2019-12-11 16:53:48
问题 I have just started working on powershell. I have two lists of 132 and 134 records each. They have 85 records in common and I want to get the values which are in list1 but not in list2 in a seperate list say list_out1 and the values which are in list2 but not in list1 in another list say list_out2. I finally want to print list_out1 and list_out2. I tried to do as given in this answer but it is giving me all the values in list1 while trying to print list_out1. Also, I have tried using foreach

Function not Returning Data

╄→尐↘猪︶ㄣ 提交于 2019-12-11 14:45:15
问题 I am using PowerShell to compare the file count and size (per file extension) in 2 separate directories. $User = $env:username $pwd = pwd clear write-host "`n" write-host "`n" write-host "`n" write "The current user is: $User" write-host "`n" write "The current path is: $pwd" write-host "`n" write-host "`n" write-host "`n" write "We need to know the following information:" write "`n" write "`n" $UserDesktopPath = Read-Host "New PC User Desktop Path" # This should be the new PC Desktop Path

Is new-pssession the same as psexec?

馋奶兔 提交于 2019-12-11 14:35:29
问题 Is pssession the same as psexec ? If I use new-pssession to create a session to a remote PC, is it the same as using psexec ? If we can use invoke-command -computername to create a temporary session, what is the benefit using pssseion to create a persistent connection? Under what circumstances should I use new-pssession ? 回答1: New-PSSession is used when you have multiple commands, or even a script, to be run against a remote machine. Invoke-Command and psexec both allow you to run a single

Powershell tasks from local machine to remote machine

岁酱吖の 提交于 2019-12-11 13:59:08
问题 I am performing below tasks on remote machine from a local machine: Creating/Deleting/Modifying some directory Copying some folder from local to remote machine Installing some .exe silently with noninteractive option Exectuing some batch files I want to write a script in PowerShell. Novice to PowerShell. I have done some basic investigation of terms like "PowerShell Remoting" etc. What are the things I need to look for? Related exmple for this will help, where should I look for those? 回答1:

Resolve-DnsName inside Test-Connection

馋奶兔 提交于 2019-12-11 13:04:01
问题 I was wondering how I could return the Resolve-DnsName output from my Test-Connection script and add it to the CSV I created. I like to capture the Name, Type, TTL, Section from that please. Only invoke the Resolve-DnsName when the ping is not successful. $servers = Get-Content "servers.txt" $collection = $() foreach ($server in $servers) { $status = @{ "ServerName" = $server; "TimeStamp" = (Get-Date -f s) } $result = Test-Connection $server -Count 1 -ErrorAction SilentlyContinue if ($result)

How to remove Braces/Curly Brackets from output -Powershell

好久不见. 提交于 2019-12-11 12:58:38
问题 How to remove Braces/Curly Brackets from output $t = [ADSI]"WinNT://$env:COMPUTERNAME" $t1 = $adsi.PSBase.Children |where {$_.SchemaClassName -eq 'user'} $t1 |select Name,Fullname Name Fullname ---- -------- {Anon} {Anon Xen1} {Anon1} {Anon1 Xen2} {Anon2} {Anon2 Xen3} 回答1: The reason there are curly braces in the first place is because the Name and FullName properties are collections not strings. Specifically they are System.DirectoryServices.PropertyValueCollection objects. $t = [adsi]"WinNT

Get-ADUser with display name as a value

两盒软妹~` 提交于 2019-12-11 12:20:00
问题 **I have list of users display name in CSV file and I am trying to get samAccountName and export it to CSV file but its not working, I understand that get-aduser doesnt accept display name as a value so I used filter but still not work help please:) CSV file format User Amer, john Doe, John smith, john ** $list = Import-Csv C:\export.csv foreach ($user in $list) { Get-ADUser -filter { DisplayName -eq "user.user" } | Select samAccountName | Export-csv C:\export1.csv } 回答1: Try ForEach($user in