powershell-5.0

Debug-Job :The job cannot be debugged because the host debugger mode is set to None or Default

杀马特。学长 韩版系。学妹 提交于 2019-12-08 05:57:23
问题 I created a sample powershell project with a Script.ps1 file and a Modules\Script1\Script1.psm1 file. the module file.. # Script1.psm1 function Get-Greeting{ Start-Sleep -Seconds 10 Write-Host "hello from foo"; } and the script file.. # Script1.ps1 if(-not(Get-Module -Name "Script1")){ Import-Module .\Modules\Script1 } if(Get-Module -Name "Script1"){ Remove-Module Script1; Import-Module .\Modules\Script1; } Get-Greeting # output: hello from foo $ajob = Start-Job -ScriptBlock { Get-Greeting }

Debug-Job :The job cannot be debugged because the host debugger mode is set to None or Default

杀马特。学长 韩版系。学妹 提交于 2019-12-08 05:29:31
I created a sample powershell project with a Script.ps1 file and a Modules\Script1\Script1.psm1 file. the module file.. # Script1.psm1 function Get-Greeting{ Start-Sleep -Seconds 10 Write-Host "hello from foo"; } and the script file.. # Script1.ps1 if(-not(Get-Module -Name "Script1")){ Import-Module .\Modules\Script1 } if(Get-Module -Name "Script1"){ Remove-Module Script1; Import-Module .\Modules\Script1; } Get-Greeting # output: hello from foo $ajob = Start-Job -ScriptBlock { Get-Greeting } -InitializationScript { if(-not(Get-Module -Name "Script1")){ Import-Module 'C:\Users\suyashs\Documents

How to run the .reg file using PowerShell?

浪子不回头ぞ 提交于 2019-12-07 14:41:02
问题 I want to run the .reg file (registry file) using PowerShell Script but I am not able to run it. When i run it manually it creates the respective nodes in registry but i want it execute using powershell script. Below is the code which i tried using but got no results - $PathofRegFile="c:\file.reg" regedit /s $PathofRegFile Another code which i tried was this - Start-Process -filepath "C:\windows\regedit.exe" -argumentlist "/s c:\file.reg" Please Help..! Below is the Content of my .reg file

Run powershell command as currently logged in user

送分小仙女□ 提交于 2019-12-07 11:58:47
问题 Given a powershell script that runs as Local System ( nt authority\system ). Is there a way to execute a command as the currently logged in user (without specifying the user password of course) ? From what I've experimented so far is the Register-ScheduledTask cmdlet which takes an -User param. The task was scheduled and run successfully, but only works when the user is logged in. Is there a better way to do it ? 回答1: I use schtasks.exe. I am not sure if this can be done in pure PS. $user =

Parsing local HTML file using New-Object -ComObject “HTMLFile” broken?

半世苍凉 提交于 2019-12-07 07:32:30
问题 I have been running a password expiration script for the pass 6 months without any issue. The script will read in a static html file and change around some of the content in memory and then an html email will be sent to all users who have expiring passwords. The script seems to have broke in the past week or so. Upon further investigation I've narrowed down the errors to the section where Powershell is supposed to create a new ComObject and write that HTML file to the ComObject. I now get the

How do you apply multiple DSC configurations?

假装没事ソ 提交于 2019-12-07 01:50:32
问题 Here's my example: $Config = @{ AllNodes = @( @{ NodeName = 'localhost'; PSDscAllowPlainTextPassword = $True } ) } Configuration LocalAdmin { Param([String[]]$Node='localhost',[PSCredential]$Cred) Import-DscResource -ModuleName 'PSDscResources' Node $Node { User 'LocalAdmin' { Username = 'Admin' Description = 'DSC configuration test' Ensure = 'Present' FullName = 'Administrator Extraordinaire' Password = $Cred PasswordChangeRequired = $False PasswordNeverExpires = $True } Group 'AddToAdmin' {

The term 'Invoke-WebRequest' is not recoginzed as the name of a cmdlet

拥有回忆 提交于 2019-12-06 16:41:45
问题 I've got problem with executing Invoke-WebRequest cmdlet. I read that ~100% case of that scenario is PS version lower than 3, but it's not my case: Name Value ---- ----- WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 CLRVersion 4.0.30319.34011 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.10208.0 PSVersion 5.0.10208.0 SerializationVersion 1.1.0.1 I can add that I'm using Windows 10 IoT Core version of OS. In fact my main purpose is execution of simple web request, but I

Powershell5 Compact code by combining foreach, begin, process, and replace command

浪子不回头ぞ 提交于 2019-12-06 05:47:09
Can I get the same results with less code? The code searches sample.bat for the strings AROUND LINE {1-9999} and LINE2 {1-9999} and replaces {1-9999} with the {line number} the code is on. sample.bat: AROUND LINE 262 LINE2 1964 Old code: gc $env:temp\sample.bat | foreach -Begin {$lc = 1} -Process { $_ -replace "AROUND LINE \d*", "AROUND LINE $lc"; $lc += 1 } | Out-File -Encoding Ascii $env:temp\results.bat (gc $env:temp\results.bat) | foreach -Begin {$lc = 1} -Process { $_ -replace "LINE2 \d*", "LINE2 $lc"; $lc += 1 } | Out-File -Encoding Ascii $env:temp\results.bat Current code: (gc $env:temp

How to run the .reg file using PowerShell?

ぐ巨炮叔叔 提交于 2019-12-05 21:06:49
I want to run the .reg file (registry file) using PowerShell Script but I am not able to run it. When i run it manually it creates the respective nodes in registry but i want it execute using powershell script. Below is the code which i tried using but got no results - $PathofRegFile="c:\file.reg" regedit /s $PathofRegFile Another code which i tried was this - Start-Process -filepath "C:\windows\regedit.exe" -argumentlist "/s c:\file.reg" Please Help..! Below is the Content of my .reg file Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\SePI] [HKEY_LOCAL_MACHINE\SOFTWARE\SePI

Run powershell command as currently logged in user

情到浓时终转凉″ 提交于 2019-12-05 18:34:45
Given a powershell script that runs as Local System ( nt authority\system ). Is there a way to execute a command as the currently logged in user (without specifying the user password of course) ? From what I've experimented so far is the Register-ScheduledTask cmdlet which takes an -User param. The task was scheduled and run successfully, but only works when the user is logged in. Is there a better way to do it ? I use schtasks.exe. I am not sure if this can be done in pure PS. $user = Get-WmiObject -Class win32_computersystem | % Username $computer = $env:COMPUTERNAME $time = (Get-Date)