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

Get the largest video files except few directories

$
0
0

Hello everyone,

I am writting a script to get the largest video files on network, except few directories. I have a problem with Get-ChildItem cmd let. I am using include and exclude in pipe and it won't work:/. I had to use a pipe between Get-Item and Get-ChildItem because of excluding directories. It didn't work when I have just GCI. I show you:

$path = Read-Host -Prompt "Type unit what you want to scan"
try{$exclusion = (Read-Host "enter users login what you want to exclude").split(',') | % {$_.trim()}}
catch{
Write-Host "nobody to exclude"
}

##Find out the files greater than equal to below mentioned size
$size = 20MB

##Limit the number of rows
$limit = 20

##Find out the specific extension file
$Extension = @("*.avi","*.mkv","*.mov","*.mp4","*.mpg","*.wmv")

##script to find out the files based on the above input


$largeSizefiles = Get-Item -Path $path -Exclude $exclusion | Get-ChildItem -recurse -Include $Extension | ? { $_.GetType().Name -eq "FileInfo" } | sort-Object -property length -Descending | Select-Object @{Name="SizeInMB";Expression={$_.Length / 1MB}}, FullName -first $limit
$largeSizefiles  |Export-Csv D:\Temp\largeFilesReport.csv

Now it exclude directories what I want but it will find all extensions, not just what I wanted.

Thanks for any advice. I am being quite desperate:)


Security problems with executing powershell script with Windows 8

$
0
0

Hello,

I have a problem with executing a  Powershell script on Windows 8 that is executing fine on Windows 7.

The script does the following:
1) Applies a snapshot on a vm in Hyper-V and starts the vm;
2) Copies some files;
3) Starts a new session, because it has to install a problem.
When I run the whole script it stops at 3 and returns the following message:

new-PSSession :  Connecting to remote server NLvSRV-9686 failed with the following error message : WinRM
cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over
the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By
default, the WinRM firewall exception for public profiles limits access to remote computers within the same local
subnet. For more information, see the about_Remote_Troubleshooting Help topic.

When I skip 1 and 2 the session is connected without any problems. I tried everything .. changing permissions, UAC ..

Somehow hyper-v and new session don't work together. I will post the script if it needed..

Can someone help me?

Windows Powershell 3.0 get/set Single A record From group of same name A records using get/set-DnsServerResourceRecord

$
0
0

hi there, i made a program about a mounth ago which updated my A Records for my DNS server, this was great as at the time i only had one DNS server, and had a DYnamic IPv4 public adress

however i now have two DNS servers -one Primary, one Secondary- replicating the primary

however when updating my script no longer works, as i also now have 2 web servers so2 A records.

here is my original code.

import-module -name DnsServer
$ip = (Invoke-WebRequest ip.mikster22.co.uk/ip.php).Content
$newip = $ip.TrimEnd( )
$oldobj = get-dnsserverresourcerecord  -zonename "mikster22.co.uk" -rrtype "A" -node
$newobj = get-dnsserverresourcerecord  -zonename "mikster22.co.uk" -rrtype "A" -node
$newobj.recorddata.ipv4address=[System.Net.IPAddress]::parse($newip)
Set-dnsserverresourcerecord -newinputobject $newobj -OldInputObject $oldobj -zonename "mikster22.co.uk"
echo "mikster22.co.uk - A Records: updated"
read-host

Here are the DNS Records:

Power Shell Dns Records

As you can see, i have my (Local Server IP-Which i can't delete) Primary Nameserver and Secondary Nameserver. both of which also have a Web server.
When running my script-Yes i may want to update both, but i will probably run two separate scripts for this.

i want to know How to specify which record to update. 

is there a way, of piping the output to a new variable, and telling this new variable to choose one the first / second line? 

i also have a script which gets the secondary DNS server's IP 

you may be wondering why i have specified two Web servers, this is because both servers are lowpowered, and based at home, with internet limits, power cuts, and obviously the need to turn of a server, my plan is to get more Servers at Geographically wide locations and thus have a (low level) of redundancy.
 


Michael Booth

Limit running time for a function?

$
0
0

Hi. 

I am trying to create a Powershell Form application for fun. It seems like most things are working as they should, but I am struggeling to find out how I can set a time-limit for my function to run. The main goal is to let the user enter the desired number of minutes a ping should run against a target computer. The pingInfo function should then run as long as the user have entered. Beeing a Powershell n00b I am still trying to learn some magic:) The next objective would be to have this little application write the info from the console to file so I can have all log-files that are mentioned in this script. The app contain a couple more files that I can post if it would help (global, and startup). Can anyone tell me where I have screwed things up? The application keeps pinging forever as it is now, so I would be happy if someone could help me out here. Thanks! :) 


$OnLoadFormEvent={
#TODO: Initialize Form Controls here
$Form=$MainForm
$Form.Controls.Add($textboxFind)
$Form.Controls.Add($textboxtime)
$Form.Controls.Add($logfoldernametext)
$Form.Controls.Add($cmdoutput)
$Form.Controls.Add($exitbutton)
$Form.Controls.Add($buttonBrowseFolder)
$Form.Controls.Add($logfolderapply)
$Form.Controls.Add($viewlogsbutton)
$Form.Controls.Add($logallno)
$Form.Controls.Add($logallyes)
$Form.Controls.Add($startpingbutton)
$Form.Controls.Add($stopping)

}

#Initializing Functions

# FUNCTION: Show an Open Folder Dialog and return the directory selected by the user.
function BrowseFolder()
{
   $logfoldername=$parameters['A']
   explorer.exe $logfoldername
}

function pingInfo {
$target=$textboxFind.text #we're taking the text from the input box into the variable $serverinfo
$pingtime=$textboxtime.text
if ((($target).length) -lt "1") {
Write-Output "No Target IP Specified." 
Write-Output "EXAMPLE: Check-Pings.ps1 www.google.com" 
break
}
$didnt = 0
$worked = 0
$datetime = (get-date)

Write-Host "`nLoading..." -nonewline -foregroundcolor yellow 
$ping = new-object System.Net.NetworkInformation.Ping 
Write-Host "`rStarted ping to $target $datetime`n" 

while (1) {

$go = $ping.send("$target") 
$result = $go.status 
$ms = $go.roundtriptime 
$ip = ($ping.send("$target").address).ipaddresstostring | foreach-object {
    $cmdoutput.lines = $cmdoutput.lines + $_
    $cmdoutput.Select($cmdoutput.Text.Length, 0)
    $cmdoutput.ScrollToCaret()
    $MainForm.Update()}

if ($result -match "Success") {
$time = (get-date)
$worked = ($worked + 1) 
if ($didnt -gt "0") {
$failrate = ( ($didnt / $worked ) * 100).tostring(".0")
Write-Output  `r"Ping Successful ($ip) - $time - $failrate% Loss - $ms ms                     " | Out-File "C:\$LogFoldername\Success_With_Failrate.log"
}
else {
Write-Output `r"Ping Successful ($ip) - $time - 0% Loss - $ms ms " | Out-File "C:\$LogFoldername\Success.log"
}
}
Else {
$time = (get-date)
$didnt = ($didnt + 1)
if ($worked -gt "0") {
$failrate = ( ($didnt / $worked ) * 100).tostring(".0")
            $errormessage = "Ping Failed - $ip - $time - $failrate% Loss ($didnt lost)                    "
Write-Output "                 " 
            $errormessage | Out-File "C:\$LogFoldername\Ping_Failed.log"
}
else {
$didnt = ($didnt - 1)
Write-Output `r"$ip - $time - Host not sucessfully pinged yet. " | Out-File "C:\$LogFoldername\Not_Successfull_Yet.log"
}
}
sleep -milliseconds 500

}
}#End of Ping Function


#End of function initializing

$exitbutton_Click={
#TODO: Place custom script here
[environment]::exit(0)
exit
}

$cmdoutput_TextChanged={
#TODO: Place custom script here
$cmdoutput.Text=pingInfo
}

$startpingbutton_Click={
#TODO: Place custom script here
    pingInfo
#TODO: Find some cool way to let the function run for a limited time. This time-limit should be taken from the variable $pingtime
}


$viewlogsbutton_Click={
BrowseFolder
}

$logfolderapply_Click={
#TODO: Place custom script here
$logfoldername=$logfoldernametext.text
$parameters['A'] =$logfoldernametext.Text
$parameters | Export-Clixml -Path "C:\$Foldername\$ConfigName"
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[Windows.Forms.MessageBox]::Show(“You have changed the default location for PingChekcer logs. Logs will now be saved in $logfoldername.”, 
“Logs will be saved in new location!”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)

}

$logfoldernametext_TextChanged={
#TODO: Place custom script here

}

$buttonBrowseFolder_Click={
if($folderbrowserdialog.ShowDialog() -eq 'OK')
{
$logfoldernametext.Text = $folderbrowserdialog.SelectedPath

}
}

$stopping_Click={
#TODO: Place custom script here
Exit
}


Best Regards Thomas Mortsell

Read-Host Default statement

$
0
0

So my script looks like this

1$UserIopsIntervalInput = Read-Host "(IOPS - sample interval), How often do you want a sample taken (in seconds, default is 1)"
2$UserIopsPeriodInput = Read-Host "(IOPS - time to run), How long do you want to run your samples for (in seconds, default is 7200)"
3$IOPsJobsInput = Read-Host "(IOPS - Job amount), How many times would you like to execute (IOPS - time to run)"
4
5$RunNow = Read-Host "Would you like to run this script now (y/n)"
6
7IF ($RunNow -eq "n")
8
9{
10$RunWhen = Read-Host "When would you like to run the script (In Seconds)"
11Start-Sleep $RunWhen
12}
13
14$workingdir = "$installpath\tmp\"
15$scriptpath = "C:\Program Files\BSTATS\bid-perfget.ps1"
16
17
18"BSTATS running...."
19
20foreach($i in (1..$UserIopsPeriodInput)) {
21    $percentage = $i / $UserIopsPeriodInput
22    $remaining = New-TimeSpan -Seconds ($UserIopsPeriodInput - $i)
23    $message = "{0:p0} complete, remaining time {1}" -f $percentage, $remaining
24    Write-Progress -Activity $message -PercentComplete ($percentage * 100) -Status "Working, Please Wait ..."
25    Start-Sleep 1
26}
27
28for ($i=0; $i -lt $IOPsJobsInput; $i++) {
29$currentdatetime = Get-Date -format M.d.yyyy.HHmmss
30
31$iopsargs = ($installpath, $customerident, $email, $emailserver, $computer, "IOPS", "IOPS-$customerident-$currentdatetime",                                  32 $UserIopsIntervalInput, $UserIopsPeriodInput, $workingdir)
33$iops = Start-Job -filepath $scriptpath  -ArgumentList $iopsargs
34
35Wait-Job $iops
36
37Remove-Job $iops
38
39}

It all works great except what I would like to know is how I can have it so if they just hit [ENTER] then it will use the default value.  for example.

in line 1:

$UserIopsIntervalInput = Read-Host "(IOPS - sample interval), How often do you want a sample taken (in seconds, default is 1)"

If the user just hits [ENTER], I would like it to use the default value of "1"

I'm not sure how I can do that.

Export-CSV does not place the data into seperate columns

$
0
0

Hi Gurus,

I am trying to create an inventory from my environement. If I run the following command it doesn't save the data into seperate columns. As a result I don't have the option to filter the information. My command is as follows:

Get-ADComputer -Filter * -Property * | Select-Object Name,DNSHostName,OperatingSystem,LastLogonDate,OperatingSystemVersion | Export-CSV AllWindows.csv -NoTypeInformation -Encoding UTF8

I would really appreciate your help.

Kinds regards,

Cengiz Kuskaya

set .sql file as variable

$
0
0

I have a powershell script where I set the variable based on a query like this:

    $Query = "SELECT 
                 t1.BSM_NM
                ,t1.D_DTM AS MAXDATETIME
                ,CASE
                    WHEN SUM(t1.V_CUST_BLK_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.MAJOR_VOICE_BLOCK) AND SUM(t1.V_CUST_BLK_CNT)/SUM(t1.V_ATT_CNT) < MAX(t2.CRITICAL_VOICE_BLOCK)
                         OR
                         SUM(t1.V_DRP_CALL_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.MAJOR_VOICE_DROP) AND SUM(t1.V_DRP_CALL_CNT)/SUM(t1.V_ATT_CNT) < MAX(t2.CRITICAL_VOICE_DROP)
                         OR
                         SUM(t1.V_AXS_F_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.MAJOR_VOICE_AXSFAIL) AND SUM(t1.V_AXS_F_CNT)/SUM(t1.V_ATT_CNT) < MAX(t2.CRITICAL_VOICE_AXSFAIL)
                    THEN 1
                    WHEN SUM(t1.V_CUST_BLK_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.CRITICAL_VOICE_BLOCK)
                         OR
                         SUM(t1.V_DRP_CALL_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.CRITICAL_VOICE_DROP)
                         OR
                         SUM(t1.V_AXS_F_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.CRITICAL_VOICE_AXSFAIL)
                    THEN 2
                    ELSE 0
                 END MAJORCRITICAL
                FROM DMSN.DS3R_FH_1XRTT_BTS_LVL_KPI t1
                INNER JOIN
                ZDMSN.DS3R_1XRTT_TRIGGERS_THRESHOLD t2
                ON
                t1.BSM_NM = t2.BSC_NM
                WHERE t1.BSM_NM = 'ARL1' and t1.D_DTM = (SELECT MAX(D_DTM) FROM DS3R_FH_1XRTT_BTS_LVL_KPI WHERE BSM_NM = 'ARL1')
                GROUP BY
                t1.BSM_NM, t1.D_DTM"  

How do I set it to an .sql file instead writing on the query in script itself?

enable/disable outlook rule

$
0
0
Is there a way to enable/disable a local client outlook rule through powershell?

Changing .Value To.MB

$
0
0

I am running the following query but I'm not able to convert the value to MB
,@{Label="Test";Expression={$_.ProhibitSendQuota.Value.ToMB()}}

Not sure what I'm doing wrong, the attribute is empty:

(Get-MailboxStatistics -server "Mail01-NY" | Where {(!($_.StorageLimitStatus -match "BelowLimit|NoChecki
ng"))} | Select-Object DisplayName -ExpandProperty DisplayName) | Get-Mailbox | Select-Object DisplayName,Alias,ServerNa
me,UseDatabaseQuotaDefaults,IssueWarningQuota,@{Label="Test";Expression={$_.ProhibitSendQuota.Value.ToMB()}}

Any way to run a powershell script in a directory with spaces in it, just by doubleclicking on it.

$
0
0

Hello,

Is there anyway to run a powershell script in a  directory with spaces in it, just by doubleclicking on it?

For example I browse to c:\my folder with explorer and click on myscript.ps1, it won't run.  It runs just fine if I open a powershell console.

-Eric

Problem creating OUs with Powershell

$
0
0

Hello Everyone:

I could use a bit of a hand: I am trying to automate the process of OU creation using Powershell.

Problem: I am able to create a base OU named Managed Objects and place a sub OU under Managed Objects, but I can not place any OUs under my Managed Objects sub OU.

How can achieve this using something like: New-ADOrganizationalUnit -Name "Tax Prep" -Path "ou=Managed Objects,dc=$StrDCName,dc=$StrDCSuffix"

I tried doing: New-ADOrganizationalUnit - Name "Workstations" -Path "ou=Managed Objects, ou=Tax Prep,dc=$StrDCName,dc=$StrDCSuffix but that did not seem to work.

Any help would be greatly appreciated!

Powershell Script Quest One Snap-in Slow When Not Logged Into Domain

$
0
0

I have a powershell script that uses the Quest One ActiveRoles Management Shell for Active Directory snap-in.  

Scenario 1

When I'm in the office, the script runs very quickly (1 min).  No errors.

Scenario 2

When I take my laptop home, and log into the laptop using the same account (although I'm not connected to the domain), the script takes 20 minutes to complete.  No errors.

I have Internet access both at work and at home.

Script Code:

Function TestImport($a)
{
    Get-Date
    Write-Host "Importing CRL"
    $Q_CRL = Import-QADCertificateRevocationList -FileName $a
    Write-Host "Import Complete"
    $CRL_ThisUpdate = $Q_CRL.EffectiveDate
    $CRL_NextPublish = $Q_CRL.NextPublish
    $CRL_NextUpdate = $Q_CRL.NextUpdate
    Write-Host "CRL Effective Date/Time: $CRL_ThisUpdate"
    Write-Host "CRL Next Publish Date/Time: $CRL_NextPublish"
    Write-Host "CRL Next UPdate Date/Time: $CRL_NextUpdate"
    Get-Date
}

TestImport "C:\TEMP\My.CRL"

The slowness occurs when the script starts the import using the snap-in.

Get-PSSnapin returns the following:

Name        : Microsoft.PowerShell.Core
PSVersion   : 3.0
Description : This Windows PowerShell snap-in contains cmdlets used to manage components of Windows PowerShell.

Name        : Quest.ActiveRoles.ADManagement
PSVersion   : 1.0
Description : This Windows PowerShell snap-in contains cmdlets to manage Active Directory and Quest One ActiveRoles.

Get-ExecutionPolicy shows: RemoteSigned

Does anyone have any ideas as to why the snap-in would be running so slowly?  All the other parts of the script seem to run just fine; no slowness.  Any help would be greatly appreciated.

-m



How can I combine this query?

$
0
0
$Username = Read-Host "Username"
Write-Host "Searching Domain Controllers..."
$DomainControllers = Get-ADDomainController -Filter *

     ForEach($Controller in $DomainControllers)
            {
                Get-ADUser -Identity $Username -Server $Controller.Hostname -Properties AccountLockoutTime,LastBadPasswordAttempt,BadPwdCount,LockedOut | Format-Table @{name="Domain Controller ";Expression={$Controller}},AccountLockoutTime,LastBadPasswordAttempt,BadPwdCount,LockedOut -AutoSize
            }

Hi Everyone,

Thank you for taking the time to read my post, it's greatly appreciated. I've asked a similar question like this but I think it's different enough to warrant a new question as the other answer was for something different to my eyes. When I run the above script (which is part of a larger function) it brings back all the data I'm looking for in the below format, but for each domain controller so it'll return about 12 different headers which isn't as clean as I would like it to be.

Domain Controller  AccountLockoutTime LastBadPasswordAttempt BadPwdCount LockedOut
--------------------  ----------------------- ---------------------------- ---------------  -----------

My question: Is it possible for me to have this output under the same table instead of 12 individual ones without the use of third party plugins?

wmi filter only works when negated twice

$
0
0

Has anyone ever saw this before and/or do they know whats causing it?  When i try to run the query with the filter of 10.1.% it doesn't return anything.  But when I negate the filter twice, I am actually getting the data I was looking for?!?! 

PS C:\> gwmi -Namespace root\microsoftdns microsoftdns_atype -Filter "IPaddress LIKE '10.1.%'" | Select IPAddress -First 10
PS C:\> gwmi -Namespace root\microsoftdns microsoftdns_atype -Filter "NOT NOT IPaddress LIKE '10.1.%'" | Select IPAddress -first 10

IPAddress
---------
10.1.91.3
10.1.91.4
10.1.91.1
10.1.91.5
10.1.91.6
10.1.91.2
10.1.27.45
10.1.27.41
10.1.72.9
10.1.27.61


PS C:\>

How to know when an install is done installing

$
0
0

I am trying to install a patch via powershell but i cant figure out how to know when it is done installing.

Powershell returns before it is done installing. What i think is happening is when i call the patch wusa is what is launched from there TrustedInstaller is called but powershell returns when wusa is done. I cant wait till TrustedInstaller is done as it never exits. Thoughts?  

start-process .\Windows6.1-KB2506143-x86.msu -Wait -ArgumentList "/quiet /norestart"
Enable-PSRemoting –force

Enable-PSRemoting is ran to soon.


Importing from csv and Exporting to csv in Powershell to query AD

$
0
0

Hi,

Here's the story, i have a csv file that has close to 10000+ users listed in AD. The csv file has their name and title. (EX: Doe John, Manager)

I'm trying to see if it's possible to query AD for the User Logon Name (which is unique to each user) using the said csv file and then export the results in another csv file.

Reading through some forums, it sounds like the best way to do this is via PowerShell Scripting (maybe LDAP, is this possible?)

I'm trying to find the best process to do this.

Any help is much appreciated.

Thanks,

Biscuit_Deere

Remoting issues

$
0
0

Very new to powershell here........I've got a script that I've pieced together to remove and reinstall java.  The script runs fine locally, runs fine when I enter-pssession on a remote workstation and kick it off......however, running with invoke-command -computername PC1 -filepath c:\scriptname.ps1 the re-install portion of the script doesn't work.  All workstations are Win7 64-bit and on the same domain.  Users of the remote machines don't have administrative rights (not sure if that's relevant here).  Remoting has been enabled via GPO.

# Script to update Java
# If there is a previous version installed we need to stop the process
if (Get-Process -Name Java -ea SilentlyContinue) {Stop-Process -Name Java -Force}

if (Get-Process -Name jucheck -ea SilentlyContinue) {Stop-Process -Name jucheck -Force}
 
if (Get-Process -Name JP2Launcher -ea SilentlyContinue) {Stop-Process -Name JP2Launcher -Force}
 
if (Get-Process -Name javaw -ea SilentlyContinue) {Stop-Process -Name javaw -Force}
 
# Now we need to uninstall the old version!
 
$app = Get-WmiObject -Class Win32_Product | Where-Object { 
    $_.Name -like "*Java 7*"
}
foreach ($a in $app) {$a.Uninstall()}

# Now we need to install the updated version!

$CMD = 'c:\windows\deploy\java.exe'
$arg1 = '/s'
 
& $CMD $arg1

reading multiple row lines from query in power shell.

$
0
0

I currently have a powershell script that returns one row of data, the script goes like this:

    $Query = "SELECT 
                 t1.BSM_NM
                ,t1.D_DTM AS MAXDATETIME
                ,CASE
                    WHEN SUM(t1.V_CUST_BLK_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.MAJOR_VOICE_BLOCK) AND SUM(t1.V_CUST_BLK_CNT)/SUM(t1.V_ATT_CNT) < MAX(t2.CRITICAL_VOICE_BLOCK)
                         OR
                         SUM(t1.V_DRP_CALL_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.MAJOR_VOICE_DROP) AND SUM(t1.V_DRP_CALL_CNT)/SUM(t1.V_ATT_CNT) < MAX(t2.CRITICAL_VOICE_DROP)
                         OR
                         SUM(t1.V_AXS_F_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.MAJOR_VOICE_AXSFAIL) AND SUM(t1.V_AXS_F_CNT)/SUM(t1.V_ATT_CNT) < MAX(t2.CRITICAL_VOICE_AXSFAIL)
                    THEN 1
                    WHEN SUM(t1.V_CUST_BLK_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.CRITICAL_VOICE_BLOCK)
                         OR
                         SUM(t1.V_DRP_CALL_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.CRITICAL_VOICE_DROP)
                         OR
                         SUM(t1.V_AXS_F_CNT)/SUM(t1.V_ATT_CNT) >= MAX(t2.CRITICAL_VOICE_AXSFAIL)
                    THEN 2
                    ELSE 0
                 END MAJORCRITICAL
                FROM DMSN.DS3R_FH_1XRTT_BTS_LVL_KPI t1
                INNER JOIN
                ZDMSN.DS3R_1XRTT_TRIGGERS_THRESHOLD t2
                ON
                t1.BSM_NM = t2.BSC_NM
                WHERE t1.BSM_NM = 'ARL1' and t1.D_DTM = (SELECT MAX(D_DTM) FROM DS3R_FH_1XRTT_BTS_LVL_KPI WHERE BSM_NM = 'ARL1')
                GROUP BY
                t1.BSM_NM, t1.D_DTM"      

    $data_set = new-object system.data.dataset
    $adapter = new-object system.data.oracleclient.oracledataadapter ($Query, $Connection)
    [void] $adapter.Fill($data_set)
    $table = new-object system.data.datatable
    $table = $data_set.Tables[0]
    $bsmNM = $data_set.Tables[0].Rows[0].BSM_NM
    $maxDT = $data_set.Tables[0].Rows[0].MAXDATETIME
    $majorC = $data_set.Tables[0].Rows[0].MAJORCRITICAL  

        if ($majorC -eq "1" )

the above query would return results in one row like this:



now, lets say I change it so it returns between 2 and 10 rows of data, and if there is just a 1 in the MAJORCRITICAL column, to do something and if there is a 1 and a 2 in the MAJORCRITICAL column to do something else. The query would now return data as such



How can I set it to read through multiple row results in the query?









How to Set-Timeout for the Cmdlet "Get-Service"

$
0
0

Hi Team,

I am Running an Script for Filling some of our Automation Need, One Part of the Script Code Use the Get-Service Cmdlet to fetch the data  if the necessary Service is installed on the Target Server.

I have Observed on one of the Server randomly the Script Stop to Respond because of this below Code . as it not able to get an output & proceed Further.

"Get-Service -Computername <NetbiosName> -Name HealthService"

Can Somebody help me understand if I want only the above Cmdlet to wait for 2 min for checking the status , how shall I proceed with that in PowerShell.

My Idea is here is check for an service if present then ignore , if not present on the target server then output it to an txt file . which is processed later in the Script.

Regards,

Jason Aranha


Jason Aranha

Windows Management Framework 3.0 and PS Remoting

$
0
0

Hello, after upgrading my Windows 7 x86 clients to WMF 3.0, I can no longer PS Remote to those machines (using Invoke-Command or Enter-PSSession).  The same update, applied to Windows 7 x64, does not render the same results, these clients still work fine.  The same goes for Windows Server 2008 R2 machines.  If I uninstall the update, the functionality comes back for the x86 clients.  Has anyone else seen this behavior?

Thanks!

Viewing all 21975 articles
Browse latest View live


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