Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Script block logging and system center products.

$
0
0

Ok we have to enable script block logging but what I've noticed is that sccm and scom generate tons of noise within the logs "warning 4101", which are supposed to be signs of malware. I Know these scripts are not malware but they get logged anyway and at such a high rate that its rolling our logs over more frequently then I'd like and our seim process is based on gb stored.  Is there something that I can do to get these system center products not to create false alerts.

thanks



search and replace in folder and sub-directory using a text file in a unicode environment

$
0
0

I have some *.txt files in a folder named "apple" C:\APPLE

There are some subfolders in the C:\apple but numbers are unknown 

I have a text file (say: sample.txt) , which contains a <chinese character> , a space , and the characters which want to replace

like this :

綫 &#32171;
胆 &#32966;
湶 &#28278;
峯 &#23791;

one space between the chinese char and the string.

I hope I can use this file sample.txt file , to search ALL THE text files in the C:\APPLE\ and it subdirectories , find out those chinese characters and replace with the characters after that.

I have tried sed but no luck on chinese characters.

Any one have an idea?

Powershell Script - Export Services and Compare (before & after restart)

$
0
0

Hello All,

I hoping that someone can help me (I am terrible at coding and even worse at powershell). My team performs a lot of patching/restarting of Servers - currently before we begin we log onto each server and export the services, at the end of the restarts etc we log back in and export the services again and compare to ensure that they match.

I'm looking for a way to do this quicker/easier - I discussed with a colleague who advised that we can do this via powershell, unfortunately i've been unable to get it to work, I have no idea where to start.

What i'm thinking is:

A menu screen:

1 - WMI - Pre-Patching Exports

2 - WMI - Post-Patching Exports

3 - WMI - Comparison

4 - Get Service * - Pre-Patching Exports

5 - Get Service * - Post-Patching Exports

6 - Get Service * - Comparison

With each command reads the "Server/Computer Name" from a Text file, for example:

for each Computer in $Computers {Get Service *} export to $ComputerName Before.XML

Compare $ComputerName Before.xml and $ComputerName After.xml

If anyone could help that would be great!!

How to mask the password while passing password through parameter

$
0
0

Hi

Please help me to mask the password while it is passed through a parameter in powershell .

Thanks and Regards

Subatra

How to change Welcome screen (system account) language by using PowerShell command?

$
0
0

Hi guys,

I have managed that I can change Current User format and input language by PowerShell using commands:

Set-WinSystemLocale en-US

Set-WinUserLanguageList en-US

But, is there any solution that I can change also the Welcome screen (System accounts) format and input language to en-US by some command? Of course manually you just go to Region -> Administrative -> Copy Settings. Trying to ask this because we have some script which install automatically several programs and it would be nice, if there is also the command at the beginning to change regional settings. This system account region is meaningful for programs.

Group Policy is not suitable because there is so many enviroments where to install these programs.

Hope you get what I try to ask.

Working with PDF files and itext in Powershell

$
0
0

how to work with pdf and itextsharp.dll in powershell

Reading delimited string from file and changing values

$
0
0

I'm trying to take numbers that are delimited by - in a file, add 280 to them, then output to a file... I am pulling the data like this:

$changeid = Get-Content $prevchangeid | Out-String

which gives us a return of:

320503427-331834355-313182001-358946497-339214016

How can I add 280 to each and write it out to the file again so I have this?

320503707-331834635-313182281-358946777-339214296


Test-Path incorrect file validation


The requested object could not be found

$
0
0

Hi,

What does this mean? Examples:

PS C:\Users\administrator> Resize-StorageTier -FriendlyName FS_VSC_Capacity -Size 600GB
Resize-StorageTier : The requested object could not be found.
At line:1 char:1
+ Resize-StorageTier -FriendlyName FS_VSC_Capacity -Size 600GB
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_StorageTie...osoft/Windo...):ROOT/Microsoft/...SFT_StorageTier) [Resize-StorageTier], CimException
    + FullyQualifiedErrorId : MI RESULT 6,Resize-StorageTier

PS C:\Users\administrator> Get-StorageTier -FriendlyName FS_VSC_Capacity


ObjectId               : {1}\\SEV-CLUSTER01\root/Microsoft/Windows/Storage/Providers_v2\SPACES_StorageTier.ObjectId="{554e0eb0-dc2f-4c4b-b144-e0371d4e5a7b}:ST:{f57fafae-c2d1-4f4d-9ffa-eba57121bf70}{38b68697-2667-4bf2-b1e5-b4393afea99b}"
PassThroughClass       :
PassThroughIds         :
PassThroughNamespace   :
PassThroughServer      :
UniqueId               : {38b68697-2667-4bf2-b1e5-b4393afea99b}
AllocatedSize          : 536870912000
AllocationUnitSize     : 268435456
ColumnIsolation        : PhysicalDisk
Description            :
FaultDomainAwareness   : StorageScaleUnit
FootprintOnPool        : 1073741824000
FriendlyName           : FS_VSC_Capacity
Interleave             : 262144
MediaType              : HDD
NumberOfColumns        : 8
NumberOfDataCopies     : 2
NumberOfGroups         : 1
ParityLayout           :
PhysicalDiskRedundancy : 1
ProvisioningType       : Fixed
ResiliencySettingName  : Mirror
Size                   : 536870912000
Usage                  : Data
PSComputerName         :

Whenever I try and pipe most things I get this error.

PS C:\Users\administrator> Get-StorageTier -FriendlyName FS_VSC_Capacity | Resize-StorageTier -Size 600GB
Resize-StorageTier : The requested object could not be found.
At line:1 char:49
+ ... geTier -FriendlyName FS_VSC_Capacity | Resize-StorageTier -Size 600GB
+                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_StorageTie...osoft/Windo...):ROOT/Microsoft/...SFT_StorageTier) [Resize-StorageTier], CimException
    + FullyQualifiedErrorId : MI RESULT 6,Resize-StorageTier

Powershell script to read a file

$
0
0

Hello,

I am very very new to Windows Powershell. i.e. No knowledge at all. 

I have an SQL Output contains following entries for an example:

usernamee-mail_id

Davidsdavids@outlook.com
sureshsuresh@outlook.com
...

Need to write a script which reads the text file columns of username and e-mail id: 

and send an e-mail to each individual saying something like this. 

Subject: Password expires X days

Body: 

Please log in and change the password and provide the link to change the password 


any advice on how this should be done? 

Please and thanks
Suresh
    



Run a script as hidden task scheduler with powershell

$
0
0

I want the script to work in secret. I used a code like the one below, but it gives an error.

Register-ScheduledTask -Action $(New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument 'invoke-command -scriptblock {Move-Item -Path $home\*.txt -Destination D:\ }   -executionpolicy bypass -NoExit -noprofile -WindowStyle Hidden') -Trigger $(New-ScheduledTaskTrigger -Daily -At 20:00pm) -TaskName "taskname"  -RunLevel Highest -Force


can I run the script in a secret way?

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17134.407
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.407
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Could you help?


Change date + time in file

$
0
0

Hi, 

I am very new in powershell, I hope someone will help me:

I have a file in C:\tmp\appFiles.appcache

Which contains:

CACHE MANIFEST
# Version: 2019-01-04T00:48:08.3070330+01:00

# Use from network if available
NETWORK:
*

--------------------------------------

I need to make a script to change date  + time to actual time

For example:

CACHE MANIFEST
# Version: 2019-01-19T13:55:08.3070330+01:00

# Use from network if available
NETWORK:
*-----------------------------------

Thank you for any help

Unable to do Format-Volume with NTFS

$
0
0

Trying to do a script to ease up the need for formatting a lot of USBs

How ever i had the script working fine for like 1 or 2 times. Haven't been able to do get the command working again.

Format-Volume -DriveLetter D -FileSystem NTFS -FORCE -NewFileSystemLabel USB-Drive

As said this worked fine but haven't been able to get it to work again no matter what. No matter if i recreate the script. if i change how its run. It just simply wont work with NTFS.
Im just given this error.

PS C:\WINDOWS\system32> Format-Volume -DriveLetter D -FileSystem NTFS -FORCE -NewFileSystemLabel USB-Drive
Format-Volume : Invalid Parameter
Activity ID: {4ae851bc-ecd6-49fb-99f6-bda66914b182}
At line:1 char:1+ Format-Volume -DriveLetter D -FileSystem NTFS -FORCE -NewFileSystemLa ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : InvalidArgument: (StorageWMI:ROOT/Microsoft/...age/MSFT_Volume) [Format-Volume], CimException+ FullyQualifiedErrorId : StorageWMI 5,Format-Volume

Though if i change the filesystem to FAT it works perfectly and the script continues to run.

*EDIT*
Soo for the fun of it i tried to run the script on another pc. Sure enough worked there. Still dosent explain why it fails on the 1st pc.


Get-CimInstance - WS-Management protocol Error

$
0
0

Hello Humans

I want to try and apply this to my windows 2012r2 HyperV Server.

https://www.altaro.com/hyper-v/monitor-hyper-v-performance-powershell/

But when I enter Step 2

Get-CimInstance -class Win32_PerfFormattedData_BalancerStats_HyperVDynamicMemoryVM -ComputerName $computer |
Select Name,*Memory*,*Pressure | Out-GridView

I'll get the error Message

Get-CimInstance : The WinRM client sent a request to an HTTP server and got a response saying the requested HTTP URL was not available. This is usually returned by a HTTP server that does not support the WS-Management protocol.
At line:3 char:1
+ Get-CimInstance -class Win32_PerfFormattedData_BalancerStats_HyperVDynamicMemory ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ConnectionError: (root\cimv2:Win3...DynamicMemoryVM:String) [Get-CimInstance], CimException
    + FullyQualifiedErrorId : HRESULT 0x80338113,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
    + PSComputerName        : HYPERVSRV

Only Get-CimInstance -class Win32_PerfFormattedData_BalancerStats_HyperVDynamicMemoryVM works with no errors, but you know, it's like just the half Pizza.

Message.Body is only returning '='

$
0
0

If I run $Query from below I get the results I want. However, running the whole script returns just a '=' sign in the e-mail. Am I losing the result-set because I am converting to HTML? any advice greatly appreciated. I just want the Get-PublicFolderStatistics to be put in the $Style HTML table I have specified. Any advice greatly appreciated, thanks.

$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "</style>"

$From = 'ExampleFrom@Exampledomain'
$To = 'ExampleTo@Exampledomain'
$Subject = 'ExampleSubject'

$Query = Get-PublicFolder '\ExamplePublicFolderPath' -Recurse | Get-PublicFolderStatistics | ConvertTo-Html -Head = $Style

$Message = New-Object System.Net.Mail.MailMessage $From, $To
$Message.Subject = $Subject
$Message.IsBodyHTML = 'True'
$Message.Body = $Query
$SMTPServer = 'ExampleSMTPServer' 
$Smtp = New-Object Net.Mail.SmtpClient($SMTPServer)
$Smtp.Send($Message)





Get-Date "11/‎30/‎2011 ‏‎12:38 PM"

$
0
0

Get-Date "11/‎30/‎2011 ‏‎12:38 PM"

Error:

Get-Date : Cannot bind parameter 'Date'. Cannot convert value

"11/‎30/‎2011 ‎12:38 PM" to type "System.DateTime". Error: "String

was not recognized as a valid DateTime."

I've tired every thing like ParseExact, etc - nothing seems to work with this date. I'm trying to get it into the following format, ".ToString('yyyyMMdd_HHmmss')" but can't extract the date from the string, same error no matter what I do. Other dates work fine.



ALL Folder Permissions, Ownership removed in error by user

$
0
0

The Folder on my SAN has had ALL the permissions stripped from it. I do not know how this happened it just has. The users do not have FULL control, but they have managed to break the permission and deny everyone access. This is not important as I have restored the data to a new folder.

I just want toDelete this folder e.g. N:\Folder One

I cannot delete, take ownership, change this in any way I have tried EVERYTHING. So now I just want to get rid of it. I have tried so manyPower Shell commands and options to reset the ACL, change owner, you name it I have tried. can anyone tell me how toDELETEthis folder when I have not access to it and all is does is report access denied.

THANK YOU!!!!






get-windowscapability access denied from elevated prompt

$
0
0

Hi All,

I have Windows 10 1809 and the RSAT tools are now feature on demand. No problem.

Except I run an elevated PS prompt and I get access denied when I try to run get-windowscapability or add-windowscapability

PS C:\> Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability –Online
Get-WindowsCapability : Access is denied.
At line:1 char:1
+ Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability –On ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-WindowsCapability], COMException
    + FullyQualifiedErrorId : Microsoft.Dism.Commands.GetWindowsCapabilityCommand
 
PS C:\>

I tried all the suggestions here:

http://woshub.com/install-rsat-feature-windows-10-powershell/

But there is nothing coming up about access denied. Other commandlets work OK and I have local admin rights on my machine.

Anyone have any light to shed on this please?

Thanks Tom.

FTP WebRequest StreamReader doensn't return all data

$
0
0

This issue lies between PowerShell and the .Net framework. (I think)

My goal is to list the files in a directory on an FTP server.

I am working with the .Net FtpWebRequest object.  I can connect to the FTP server, build the FtpWebRequest object, using the ListDirectoryDetails method and its related .StreamReader object.

My problem is that the StreamReader only contains information for one file, one string entry, rather than an array of strings, one for each file in the target directory.

Following is the PowerShell line invoking the GetResponseStream method.  It runs without error, as mentioned, but doesn't return all expected data.

 [System.IO.StreamReader]$oStreamReaderL = New-Object System.IO.StreamReader($Response.GetResponseStream() )

If I use simple C# console app, running against the same FTP server, the response stream contains all the expected file data.

What am I missing?

File Access Issues with Export-Csv

$
0
0

I'm executing the following PS script to retrieve a registry value from multiple remote servers and append the response to a CSV file hosted on the server running the script. Script content is as follows:

Import-Csv E:\XXX\XXX\XXXXXXX\ServersList.csv -Header 'ComputerName' | ForEach {
    Invoke-Command -Computername $_.ComputerName `
    -ScriptBlock {
        Get-ItemProperty `
        -Path "HKLM:Software\Wow6432Node\XXXXX\XXXX\XXXXX\XXXXXX\TEST" `

        -Name "State" |
Select-Object @{N="Server";E={$env:COMPUTERNAME}}, PSChildName, State |
Export-Csv -Path "\\LocalServer\E\XXXXX\XXXXX\XXXXXX\LOG\RegistryValues.log" -Force -NoTypeInformation -Append
    }
}

The registry value is logged in the CSV correctly for the local server, but an execution against a remote server always results in an Access Denied:FileOpenFailure error message.

All file and share permissions are verified as correct as far as I can tell.

Any pointers greatly appreciated!

Viewing all 21975 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>