Quantcast
Channel: Windows PowerShell Forum
Viewing all 2562 articles
Browse latest View live

Formatting Jumbled / Output with HTML guids

$
0
0

So I am trying to make reports for our servers and one thing is bizarre to me and I do not understand it.


Commands:


#List all Patches within the last 7 days and stores the results in an array variable.

[array]$Patches = Get-HotFix | ? {$_.InstalledOn -gt (Get-Date).AddDays(-7)} | Select HotfixID,InstalledOn | Sort InstalledOn | FT -AutoSize

#Create HTML file

$Patches | ConvertTo-Html -Fragment -As Table | Out-file D:\Test.html


However when viewed I always get strange data displayed.  I know this is an amatuer mistake and was hoping someone explain a better way.  Currently I have DNS checks and Ping test and uptime and when I get to the hotfixes it pushes out this data.  Thanks in advance for your kind assistance.


ClassId2e4f51ef21dd47e99d3c952918aff9cdpageHeaderEntrypageFooterEntryautosizeInfoshapeInfogroupingEntry
033ecb2bc07a4d43b5ef94ed5a35d280Microsoft.PowerShell.Commands.Internal.Format.AutosizeInfoMicrosoft.PowerShell.Commands.Internal.Format.TableHeaderInfo
9e210fe47d09416682b841769c78b8a3
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c



PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

$
0
0

Hi all,

I have new to PS and trying to run a powershell command, which is giving me error. Please let me know what I am missing here. I am having trouble to run the script to create folders and collections



PS E:\> dir SCCMTools\powershellscripts\createfoldersandcollections.ps1> Set-ExecutionPolicy RemoteSigned
Get-ChildItem : A positional parameter cannot be found that accepts argument 'RemoteSigned'.
At line:1 char:4
+ dir <<<<  SCCMTools\powershellscripts\createfoldersandcollections.ps1> Set-ExecutionPolicy RemoteSigned
    + CategoryInfo          : InvalidArgument: (:)[Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

PS E:\>

----
I think the issue with the .ps1 but I am not sure what will be the work around.
When I run this without .ps1, it gives me the below error


PS E:\SCCMTools> dir powershellscripts\CreateFoldersAndCollections
Get-ChildItem : Cannot find path 'E:\SCCMTools\powershellscripts\CreateFoldersAndCollections' because it does not exist
.
At line:1 char:4
+ dir <<<< powershellscripts\CreateFoldersAndCollections
+ CategoryInfo : ObjectNotFound: (E:\SCCMTools\po...sAndCollections:String) [Get-ChildItem], ItemNotFound
Exception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Unable to call WCF method in powershell

$
0
0

Hi Experts,

I am unable to call the method in Powershell. I am using the below powershell script to call WCF service method...

$AurionWebSvcURL = "http://sntst10/TEST/servlet/services/EV397_AURION_WS?wsdl"
$proxy = New-WebServiceProxy -Uri $AurionWebSvcURL -Namespace ExportTool  -Class Program -UseDefaultCredential
Write-host -ForegroundColor yellow  $proxy

$UC = $proxy.LOGON("b_ratra1","Friday1") 

When i run above command, it throwing following error message:

Cannot find an overload for "LOGON"  and the argument count: "2"

I found similar thread on this error as below but doest help.

http://social.technet.microsoft.com/forums/en-us/winserverpowershell/thread/7157AE5B-ABA5-4E6D-85A6-6F5C1D83D71B

Could you please advice am i using the right syntax when i am calling the method with arguements in Powershell?

Thanks in advance.


Warm Regards Badal Ratra


Powershell re-prompt for entry

$
0
0

Hello. I'm user a powershell script that prompts for multiple entries and certain entries require a user to input a particular value. What I would like to do is if the user's input is not equal to those values, re-prompt the user to enter the entry again until they do enter the correct value. So for example one input asks for a Y or N if email will be forwarded.

$WillMail = read-host "Will mail be forwarded? Enter Y or N "

Ideally if the entry is something other than "Y" or "N", I'd like it to ask something like "That is an incorrect value. Please enter Y or N".

login to a list of computers simultaneously?

$
0
0

I do not know where to start on this but i need to know how to script logging into many computers simultaneously so as a logon script will kick off.

It would be better if we had a time out/logoff command of say an hour.

I know to script the lists and for each and all that but have no clue on doing the logon /multi threaded part.

could anyone help with this?

Formatting repadmin output

$
0
0

Hi all,

I'm trying to format output of repadmin /replsummary command within powershell.

In my script, very first thing, i execute repadmin /replsummary within powershell and format output a little bit as follow:

$myRepInfo = @(repadmin /replsum * /bysrc /bydest /sort:delta)
$msg = $myRepInfo | Where-Object { $_ } | ForEach-Object { $_ -replace $_,"$_`n" }
$last = $msg -replace "Beginning data collection for replication summary, this may take awhile:",""
$last >> C:\scripts\repsummary.log

But when i try to get-content of replsummary.txt, i can not sort output using columns since within repsummary.txt there is no chance to use delimeter or columns, it's really a bad designed output.

Here is the actual repadmin /replsummary output file:

What i want to achieve is to use repsummary txt output to create a table in powershell that includes Source,Destination and Error fields only. So that i will be able to create a html table and assign red color for each failed row.

Thanks in advance.

How can I get the hardware information with Powershell

$
0
0

Hi All,

I want to use powershell to check whether a PC contains some hardware, such as USB port, Or IEEE1394 port. Or I need to control the hardware on and off.

How can I cover this.


No code, No fact.

Disk path


Use information from WMI to write values to the registry

$
0
0

Hi,

I've been using some of the code found on this page http://technet.microsoft.com/en-us/magazine/dd535685.aspx to gather Reliability Index Scores.

I'd like to know if/how to write the values this part of my code gathers to the registry please:

@("localhost") |
    foreach-object -process {
      get-wmiobject Win32_ReliabilityStabilityMetrics -computername $_ -property @("timegenerated", "SystemStabilityIndex") |
      select-object -first 6 timegenerated,SystemStabilityIndex |
      format-table
  }

As you can probably tell I'm new to PS...have mostly used VB in the past but decided its time to start moving on ;)

Thanks,

C


Carl Barrett | Twitter: @Mosquat

Creating module, Read-Host with color (Read-Host parameters problem)

$
0
0

Well my problem isn't making the color, I already did that and it works fine. I have the problem with the old parameters of the Read-Host cmdlet like -AsSecureString. Is there any way, I can say that my new function should import all the parameters from the Read-Host cmdlet and just have a new one for the color? Here's my for now working script:

#Read-Text

#You can give the Read-Host command another color instead of just white with this function.

#Example:
#Read-Text -Fore Yellow "Type something"

#You can also still save it into a variable:
#$a = Read-Host -Fore Yellow "Type something"
#Write-Host $a

Function Read-Text 
{
Param($Fore, [String]$Text)
If ($Fore)
{
[console]::ForegroundColor = $Fore
}
Read-Host $Text
[console]::ResetColor()
}

Thanks for your help.

The following is my signature:

Powershell Programmer & Advanced Lua Programmer

Location: Switzerland

Beside that, whenever you see a reply, you think is helpful, click "Vote As Helpful"! And whenever you see a reply being an answer to the main question of the thread, click "Mark As Answer" (if you opened the thread).

I published the URL's for the icons in my signature.

Please contact me, before reporting me, thank you.

[string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('577076797174-87661607769657424-8687168065964').substring(($_*2),2))})-replace' '

quota management

$
0
0

Hi all,

I'm trying to script storage quotas on a windows 2012 server. I am running the console as admin but I get the following error though;

PS C:\Windows\system32> New-FsrmQuota -CimSession Server10 -Path "C:\temp" -Description "limit usage to 20 MB based on template." -Template "20 MB Limit"
New-FsrmQuota : 0x80045301, The requested object was not found.
At line:1 char:1
+ New-FsrmQuota -CimSession Server10 -Path "C:\temp" -Description "limit usage to ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_FSRMQuota:Root/Microsoft/.../MSFT_FSRMQuota) [New-FsrmQuota], CimExc
   eption
    + FullyQualifiedErrorId : HRESULT 0x80045301,New-FsrmQuota
    + PSComputerName        : Server10

The template does exist. Any ideas what this could be?

Thanks in advance.

Unable to read XML file in Powershell

$
0
0

Hi Experts,

My xml file format as below.

<DocumentRoot>

-<AQT_Output>

<Surname>LOVE</Surname>

<Given_Names>Richard James</Given_Names>

<Email_Address>Richard.Love@XYZ.com.au</Email_Address>

<Employee_ID>1348</Employee_ID>

<Employee_Number>030-41633</Employee_Number>

<User_Name>RJLOVE</User_Name>

<Position_Title>Customer Service Officer</Position_Title>

<Area_ID>AAB01</Area_ID>

<Area_Description> House 1st Floor</Area_Description>

<Department_ID>810</Department_ID>

<Department> Retail.Customer Services.Billing</Department>

<Supervisor_Emp_No>9331</Supervisor_Emp_No>

<Supervisor_ID>7692</Supervisor_ID>

<Supervisor_User_ID>kbritton</Supervisor_User_ID>

<ESS_Authority_Level>1</ESS_Authority_Level>

</AQT_Output>

-<AQT_Output>

<Surname>OCHMANSKI</Surname>

<Given_Names>Danuta</Given_Names>

<Email_Address>Danuta.Ochmanski@XYZ.com.au</Email_Address>

<Employee_ID>352</Employee_ID>

<Employee_Number>030-42097</Employee_Number>

<User_Name>D_OCHMANSKI</User_Name>

<Position_Title>Technical Officer</Position_Title>

<Area_ID>GRENWW</Area_ID>

<Area_Description>Greenway West</Area_Description>

<Department_ID>605</Department_ID>

<Department>Network Services.Customer Service.Design</Department>

<Supervisor_Emp_No>527-42110</Supervisor_Emp_No>

<Supervisor_ID>371</Supervisor_ID>

<Supervisor_User_ID>DKCHAN</Supervisor_User_ID>

<ESS_Authority_Level>1</ESS_Authority_Level>

</AQT_Output>

</DocumentRoot>

I am unable to read XML file users attributes. Using the below Powershell script

[Xml]$xmldata=Get-Content D:\BackUp\pmis.XML
$xmldata.DocumentRoot
$xmldata.DocumentRoot.AQT_OUTPUT
#$xmldata.content.text | select English | Export-CSV D:\Backup\test123.csv -notype

$objectNodes = $xmldata.SelectNodes('/DocumentRoot/AQT_OUTPUT')
foreach($objectNodes in $xmldata.DocumentRoot.AQT_Output)
{
    Write-Host $objectNodes.Surname
}

Above script is giving me below output but i need to read Users Output. For instance, Suraname, Email ID etc

AQT_Output                                                                                                                                                                                                            
----------                                                                                                                                                                                                            
{AQT_Output, AQT_Output, AQT_Output, AQT_Output...}     

Any suggestions how should i proceed further. Thanks.


Warm Regards Badal Ratra



set default Computer to member of a group

$
0
0

Hi All,

I want to all client computer after join domain will automatically add to member of group, is there any way implement it by using script/PS maybe ?

I've already post in the Directory Services forum : http://social.technet.microsoft.com/Forums/en-US/winserverDS/thread/7e1459f2-7ebd-44f1-bb6b-c6b24846f1d7


Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Krisna Ismayanto | My blogs: Krisna Ismayanto | Twitter:@ikrisna

Trying to use Conditional Formatting with a value taken from WMI Insertion Strings, but can't convert type "System.String" to type "System.Collections.Hashtable"

$
0
0

All I want to do it create an email alert when Exchange whitespace drops below a certain level.

I have this script below working and able to output to csv/screen for checking manually, but when the if statement is added it returns this:

Bad argument to operator '-lt': Could not compare "System.Collections.Hashtable
" to "5000". Error: "Cannot convert the "5000" value of type "System.Int32" to
type "System.Collections.Hashtable".".
At line:20 char:22
+ if ($WhitespaceMB -lt <<<<  5000)
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : BadOperatorArgument

I thought that my Insertion String data is already in a hashtable?

#create variable for todays date and the export filepath/name $Date = Get-Date -Format dd-MM-yyyy $Filename = "c:\ExchTasks\LDS_WS_$Date.csv" $LeedsServer = "emailserver" # create variable for todays date from midnight while also converting WMI date $WMIToday = ([WMI]"").ConvertFromDateTime((Get-Date 00:00)) #create two calculated properties for the seperation of Insertion String values $DB = @{Name="DB";Expression={$_.InsertionStrings[1]}} $WhitespaceMB = @{Name="WhitespaceMB";Expression={$_.InsertionStrings[0]}} Get-WmiObject Win32_NTLogEvent -ComputerName $LeedsServer -Filter "Logfile='Application' AND ` EventCode=1221 AND TimeWritten>='$WMIToday'" | Select-Object ComputerName,$DB,$WhitespaceMB ` | Sort-Object DB -Unique -Descending if ($WhitespaceMB -lt 5000) { $EmailFrom = “an address” $EmailTo = “an address” $Subject = “Some text” $Body = "Some text" etc etc etc }

Powershell cmdlet not recognized

$
0
0
when i run the Get-VM cmdlet on my R2 - SP1 host - I get the error "The term Get-VM is not recognized as the name of a cmdlet, function etc. etc.   What am I missing here??

PSCmdlet.ParameterSetName

$
0
0
I'm trying to implement [CmdletBinding(DefaultParameterSetName="something")] when I'm at ProcessRecord function, I copy a switch structure as

switch (PSCmdlet.ParameterSetName)

{

}

I do have a parameter declaration with ParrameterSetName. It seems not to recognize the command in the switch. Can someone tell me where I could find the proper syntax.

michael john ocasio



WMF 3.0 installation fails with error 0x80070003

$
0
0

Hi Guys,

I'm trying to install WMF 3.0 (KB2506143) my Windows 7 x86 workstation and on some Server 2008 R2 x64 servers so I can use Powershell 3.0.  On my workstation and on one server, installation fails with error x80070003: The system cannot find the path specified.  On two other servers, installation succeeded with no problem.  I can't find any related error messages in the event logs of the machines where installation fails.  I also haven't found any references to this problem posted anywhere on the web.  I don't know how to proceed from here.  Can anyone give me a clue?

Regards,

Mike

Powershell invoke-command

$
0
0

Hi,

I would like to launch a script ps1 on a remote server.

Invoke-Command -ComputerName myserver -ScriptBlock{C:\Scripts\Script1.ps1}

The script.ps1 :

Start-Process Powershell -argumentlist "c:\Scripts\Scripts2.ps1" -Credential $(get-credential -credential domain\user)

I have the error below :

This command cannot be executed due to the error: Access is denied.
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

I tried with -credential in invoke-command but I have the same error.


Could you please help me?

Thanks.


Invoke-SqlCmd try and catch

$
0
0

There is conversion error returned by following query in SQL server.

select * from sys.databases where database_id = 'W'

Msg 245, Level 16, State 1, Line 1

Conversion failed when converting the varchar value 'W' to data type int.

Is it possible to catch this error by Powershell try catch block?

The following script does not return any error.

$SqlQuery =  "select * from sys.databases where database_id = 'W'"
try
{
$SqlResourceMon = Invoke-SqlCmd -Query $SqlQuery -ServerInstance "SQLINSTANCENAME" -Database "master" -ErrorAction Stop
}
catch 
{
$_ "error running sql $SqlQuery"
}

Trying to copy a folder from a server share to many workstations...

$
0
0

I have a folder that a vendor frequently updates and I am trying to set a powershell script to copy the updated folder to the current workstations in my environment. I want the updated folder to overwrite any old files in the folder and if the folder does not exist, create it. Attached, is the powershell script I made to do this. It states at the bottom that it completed, but when i browse to the directory on one of the workstations, the files are not there and/or not overwritten. I do not get any errors. Am i doing something wrong in my syntax?? Also, when i run this under my domain account (as you see i am running as administator) I am a local admin account on all workstations.

thank you,

Dave

Viewing all 2562 articles
Browse latest View live


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