powershell-4.0

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

Powershell v4 not importing module automatically

。_饼干妹妹 提交于 2019-12-07 10:54:32
问题 I am using Microsoft PowerShell v4 : PS C:\> get-host Name : ConsoleHost Version : 4.0 InstanceId : 3b4b6b8d-70ec-46dd-942a-bfecf5fb6f31 UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : de-CH CurrentUICulture : en-US PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace I have developed a C# project in Visual Studio 2012 targeting .NET Framework 4 which

Error PSRemoting using Session and CredSSP

半城伤御伤魂 提交于 2019-12-07 10:31:21
问题 I use Windows 8.1 Enterprise 64 bit and Powershell 4.0. I want execute powershell remoting and using authentication CredSSP. I open Console Powershell, run as Administrator, and execute Enter-PSSession command to connect to remote computer. But I get error about connection. PS C:\Documents and Settings\kiquenet> Enter-PSSession -ComputerName DC -credential devrsg.com\Administrator Anyways, I test command from Windows XP and Windows 7, and connection is OK. PS C:\Documents and Settings

In PowerShell why does “casting” to FileInfo set the wrong FullName, Directory, and DirectoryName

半世苍凉 提交于 2019-12-07 08:10:09
问题 I'm noticing a VERY odd behavior in both my PS ISE and PS when I'm getting a FileInfo object by calling $FileInfo = [System.IO.FileInfo](".\SomeFile.ext") When I look at its properties the DirectoryName and its related properties all default to the ORIGINAL path that PS opens in. Here's a copy from my ISE which launches as an administrator with c:\Windows\System32 as the default path If I run the following code: $Fileinfo = [System.IO.FileInfo](".\@OpenWithToastLogo.png") cd c:\temp

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' {

Error opening excel in powershell

主宰稳场 提交于 2019-12-07 00:54:06
问题 I need to open excel file with CorruptLoad paramterer from powershell-script. But when I try to make it, I get an error Exception calling "Open" with "15" argument(s): "open method workbooks class failed" . This error occurs only when I call Open with all 15 arguments. And when I try to open the same excel file with VB.net program with 15 arguments or with specifying value of named argument CorruptLoad , there is no problem! I'm using powershell v 4.0 , Office 2010 with SP2 and .NET Framework

PowerShell PSScriptRoot is null

喜夏-厌秋 提交于 2019-12-06 18:39:24
问题 When I run $PSScriptRoot it returns null . I am using PS version 4. $val = Join-Path -Path $PSScriptRoot WebPlatformInstaller_amd64_en-US.msi Error Join-Path : Cannot bind argument to parameter 'Path' because it is an empty string. 回答1: If using ISE use: $psISE.CurrentFile.FullPath When ISE is launched, $psISE is created and can be used to determine the current path of the ISE instance. This was introduced in version 3.0. See ISE Object Model Hierarchy If you wanted to get the path in either

Powershell: How to I test if a line of text contains line feed or carriage return?

僤鯓⒐⒋嵵緔 提交于 2019-12-06 11:38:53
How do I test if the first line of a text file is terminated with \r or \n? I tried various renditions similar to the following. I'm not sure that the string imported into powershell (first line of the file) even contains the invisible characters. I also tried using the StreamReader method to read the line to no avail. $master = Get-Content $masterFilename | Select-Object -First 1 if ($master.Contains("\r|\n")) { write-host "you betcha, there's a carriage return or line feed" } Thank you. Get-Content converts your file into a sting array based on those characters. By the time you start to test

How to elevate an already running session within its own code

无人久伴 提交于 2019-12-06 08:41:13
I'm writting a PowerShell script that configures some things in Active Directory. I need to run it as a specific user in order to get the right permissions for the process, currently i'm running the .ps1 file through a .bat file, so I can choose "run as a different user" or "run as administrator". What I'm tryng to achieve is that inside the script I will ask the user for the right credentials, and then elevate the session to run with the inputed user creds. I've tried using this within my code: Start-Process powershell.exe -Credential "TestDomain\Me" But it just opens an empty PS Session

The PowerShell provider xWebAdministration does not exist at the PowerShell module path nor is it registered as a WMI provider

穿精又带淫゛_ 提交于 2019-12-06 07:16:44
I have made this very simple DSC script. Which basically creates web application in default website. Configuration ConfigureWebApp { param ($MachineName) Import-DscResource -Module xWebAdministration Node $MachineName { xWebApplication NewWebApplication { Name = "MyApp" Website = "Default Web Site" WebAppPool = "DefaultAppPool" PhysicalPath = "C:\Inetpub\wwwroot\MyApp" Ensure = "Present" } } } cd "C:\Dsc\scripts" ConfigureWebApp -MachineName "WIN-KPURIN2B87H" When I run generated MOF file, it gives me following error. The PowerShell provider xWebAdministration does not exist at the PowerShell