powershell-5.0

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

最后都变了- 提交于 2019-12-05 13:03:57
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 error : No coercion operator is defined between types 'System.Array' and 'System.String' At line:1

How do you apply multiple DSC configurations?

爷,独闯天下 提交于 2019-12-05 06:37:04
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' { GroupName = 'Administrators' DependsOn = '[User]LocalAdmin' Ensure = 'Present' MembersToInclude =

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

我只是一个虾纸丫 提交于 2019-12-04 22:19:48
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 am interested why this cmdlet is not working, especially if more of them won't be ;/ I suppose it can

PowerShell v5 - How to install modules to a computer having no internet connection?

此生再无相见时 提交于 2019-12-04 04:50:20
I've a machine (v3, internet, no admin access) which I used to download WMF 5.0 and set up another machine(v5, no internet, admin access). Now, I want to use some modules from PowerShellGet on the machine running v5 but no internet connection. I need an option to download *.psm1 file which I can then copy over and use. Just like we have options to download from GitHub. Anyone with a similar issue and any workarounds ? Install the Package Management Module on your PowerShell 3 machine, and then use Save-Module ... Or set up ProGet somewhere "on the edge" of your network, and have it mirror the

Powershell Copy Files with a Blacklist (Exclude) and a Whitelist (Include)

风格不统一 提交于 2019-12-03 16:40:54
I'm translating some msbuild scripts to powershell. In msbuild, I can generate a blacklist and/or whitelist of files I want to (recursively) copy to a destination folder. As seen below: <?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped"> <PropertyGroup> <!-- Always declare some kind of "base directory" and then work off of that in the majority of cases --> <WorkingCheckout>.</WorkingCheckout> <WindowsSystem32Directory>c:\windows\System32</WindowsSystem32Directory> <ArtifactDestinationFolder>$

How To Access Specific Rows in an Import-Csv Array?

偶尔善良 提交于 2019-12-02 18:15:51
问题 I need to split a large file upload into many parallel processes and want to use a single CSV file as input. Is it possible to access blocks of rows from an Import-Csv object, something like this: $SODAData = Import-Csv $CSVPath -Delimiter "|" | Where $_.Rownum == 20,000..29,999 | Foreach-Object { ... } What is the syntax for such an extraction? I'm using Powershell 5. 回答1: Import-Csv imports the file as an array of objects, so you could do something like this (using the range operator): $csv

How To Access Specific Rows in an Import-Csv Array?

三世轮回 提交于 2019-12-02 10:44:12
I need to split a large file upload into many parallel processes and want to use a single CSV file as input. Is it possible to access blocks of rows from an Import-Csv object, something like this: $SODAData = Import-Csv $CSVPath -Delimiter "|" | Where $_.Rownum == 20,000..29,999 | Foreach-Object { ... } What is the syntax for such an extraction? I'm using Powershell 5. Import-Csv imports the file as an array of objects, so you could do something like this (using the range operator): $csv = Import-CSv $CSVPath -Delimiter '|' $SOAData = $csv[20000..29999] | ForEach-Object { ... } An alternative

How to access a property from an object using a variable name?

若如初见. 提交于 2019-12-01 19:49:24
问题 This works: $psISE.Options.DebugBackgroundColor = '#FFC86400' This doesn't: $attribute = 'DebugBackgroundColor' ($psISE.Options)[$attribute] = '#FFC86400' ERROR: Unable to index into an object of type Microsoft.PowerShell.Host.ISE.ISEOptions I want to set option attributes in a foreach loop using the $attribute variable. Is there a way to do this? 回答1: Just use double quotes after the dot: $attribute = 'DebugBackgroundColor' $psISE.Options."$attribute" 来源: https://stackoverflow.com/questions

New-Item changes function return value

偶尔善良 提交于 2019-12-01 11:03:45
I want to write a function that creates a folder (if it doesn't exist) with specified name inside specified folder. It's turned out that depending on calling New-Item function return different values. And I can't figure out how it's related to New-Item actually. $folderPath = "C:\tmp" function CreateFolder([string] $name, [string] $parentFolder) { $path = "$parentFolder\$name" if(!(Test-Path $path)) { New-Item -path $parentFolder -name $name -itemtype Directory } return $path } $FOLDER_NAME = "folder1" $destination = CreateFolder $FOLDER_NAME $folderPath echo $destination.GetType() If folder1

How to list VSTS agent pools programmatically from PowerShell?

六眼飞鱼酱① 提交于 2019-12-01 09:39:48
I want to connect to VSTS and get a list of agent pools. I want to enumerate the agent pools and then delete agents on the VSTS server. I can't find any documentation for how to do this in the VSTS API reference. I'm connecting to VSTS fine like this to list projects for example, but how to list agent pools? $User = 'mark.allison@domain.com' $PersonalAccessToken = '{PAT_TOKEN}' $base64authinfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User, $PersonalAccessToken))) $vstsAccount = "{VSTS_ACCOUNT}" # projects $resource = 'projects' $uri = "https://sabinio