invoke-command

powershell remote

非 Y 不嫁゛ 提交于 2021-02-10 18:10:18
问题 I am trying to run this from my local machine (Win7 & PS v2.0) cls $sess = Enter-PSSession -ComputerName blmcrmpoc Invoke-Command -Session $sess -Scriptblock { $path = "C:\inetpub\logs\LogFiles" $lastWrite = (Get-Date).AddDays(-90) $oldLogs = Get-ChildItem -path $path -Recurse -Filter *.log | Where {$_.LastWriteTime -le $lastWrite} if ($oldlogs.count -gt 0) {foreach ($log in $oldLogs) {$log.Delete()}}} But I get this error. ***Invoke-Command : Cannot validate argument on parameter 'Session'.

powershell remote

泪湿孤枕 提交于 2021-02-10 18:06:08
问题 I am trying to run this from my local machine (Win7 & PS v2.0) cls $sess = Enter-PSSession -ComputerName blmcrmpoc Invoke-Command -Session $sess -Scriptblock { $path = "C:\inetpub\logs\LogFiles" $lastWrite = (Get-Date).AddDays(-90) $oldLogs = Get-ChildItem -path $path -Recurse -Filter *.log | Where {$_.LastWriteTime -le $lastWrite} if ($oldlogs.count -gt 0) {foreach ($log in $oldLogs) {$log.Delete()}}} But I get this error. ***Invoke-Command : Cannot validate argument on parameter 'Session'.

How to save Powershell output to specific folder on the local machine when running an Invoke command on remote machine

浪尽此生 提交于 2021-02-08 10:06:14
问题 I am using powershell to pull basic computer information from all computers on a LAN. These computers are not, and will never be on, a domain. I have had some success in my test runs getting the output for all of the machines to save into the c:\scripts folder on the host machine. I am, however, having to use the Invoke-command for every cmdlet so that I can put the Output destination outside of the {}. $computers = Get-Content -Path 'c:\scripts\livePCs.txt' foreach ($computer in $computers)

How to save Powershell output to specific folder on the local machine when running an Invoke command on remote machine

坚强是说给别人听的谎言 提交于 2021-02-08 10:05:07
问题 I am using powershell to pull basic computer information from all computers on a LAN. These computers are not, and will never be on, a domain. I have had some success in my test runs getting the output for all of the machines to save into the c:\scripts folder on the host machine. I am, however, having to use the Invoke-command for every cmdlet so that I can put the Output destination outside of the {}. $computers = Get-Content -Path 'c:\scripts\livePCs.txt' foreach ($computer in $computers)

How do I pass a class object in a argument list to a another computer and call a function on it?

筅森魡賤 提交于 2021-02-08 06:39:38
问题 I am attempting to create a class object and use Invoke-Command to call a function on the class on a remote machine. When I use Invoke-Command with no computer name this works fine but when I attempt to do this on a remote computer I get an error saying the that the type does not contain my method. Here is the script I am using for testing this. $ComputerName = "<computer name>" [TestClass]$obj = [TestClass]::new("1", "2") Get-Member -InputObject $obj $credentials = Get-Credential Invoke

Encapsulate the output of invoke command in a variable - PowerShell

社会主义新天地 提交于 2021-01-27 19:23:43
问题 I have a script that installs Remote Desktop Services on remote machines (from the DC). I'm now at the phase where I check if RDS installed on the connection broker (server) and connection host (server). I want to use invoke-command since a remote powershell session seemed too complicated. This is the code I have: $res = Invoke-Command -ComputerName "testpc.eil.local" -ScriptBlock { if((Get-WindowsFeature -Name "Remote-Desktop-Services").Installed -eq 1) { #i need this output (true or false

$Using:var in Start-Job within Invoke-Command

梦想与她 提交于 2020-07-19 04:52:32
问题 I am using Invoke-Command , and within the -ScriptBlock I am using Start-Job . I have to use $Using:var within Start-Job but the session is looking for the declared variables in the local session (declared before Invoke-Command ). Here's a very brief example of what I'm doing: Invoke-Command -ComputerName $computer -ScriptBlock { $sourcePath = 'C:\Source' $destPath = 'C:\dest.zip' $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal $includeBaseDirectory = $false Start-Job

Invoke-Command on remote session returns local values

倾然丶 夕夏残阳落幕 提交于 2020-01-23 17:58:13
问题 Question Should the script block of Invoke-Command , when run with a PSSession, always run on the remote computer? Context I ran the below powershell against a list of servers: Clear-Host $cred = get-credential 'myDomain\myUsername' $psSessions = New-PSSession -ComputerName @(1..10 | %{'myServer{0:00}' -f $_}) -Credential $cred Invoke-Command -Session $psSessions -ScriptBlock { Get-Item -Path 'HKLM:\System\CurrentControlSet\Control\Lsa\Kerberos\Parameters' } | Sort-Object PSComputerName #

Invoke a second script with arguments from a script

纵饮孤独 提交于 2020-01-20 12:59:54
问题 I have a script that reads a configuration file that results in a set of name value pairs that I would like to pass as arguments to a function in a second PowerShell script. I do not know what parameters will be placed in this configuration file at design time, so right at the point where I need to invoke this second PowerShell script, I basically just have one variable that has the path to this second script, and a second variable that is an array of arguments to pass to the script

Invoke a second script with arguments from a script

送分小仙女□ 提交于 2020-01-20 12:53:28
问题 I have a script that reads a configuration file that results in a set of name value pairs that I would like to pass as arguments to a function in a second PowerShell script. I do not know what parameters will be placed in this configuration file at design time, so right at the point where I need to invoke this second PowerShell script, I basically just have one variable that has the path to this second script, and a second variable that is an array of arguments to pass to the script