Microsoft Virtualization Discussions

PowerShell behaviour

storageguy
4,225 Views

Hello PSTK experts,

 

I would like seek guidence here. When I run this code just itself it displays all the fields and values. But when it is embeded into a bigger script (similar to 83upgrade check) it just displays the just Vserver value (not even the heading)

 

Code:

 

$OpenClient = Get-NcExportRule |where-object {$_.ClientMatch -eq "0.0.0.0/0" }
If ($OpenClient) {
write-host "Found export policy with open host access, need fixed or make sure no volume uses these policies" -ForegroundColor Red
$OpenClient
}
$AnyRule = Get-NcExportRule | where-object {$_.ClientMatch -ne "0.0.0.0/0" } | where-object {$_.RwRule -ne "sys" -or $_.RoRule -ne "sys" }
If($AnyRule) {
write-host " "
write-host "Found export policy with open rule access, doesn't fit our standard and need fixed" -ForegroundColor Red
$AnyRule
}

I tried with start-sleep for 2 seconds but same results. Any help would be appreciated.

 

Thanks

 

4 REPLIES 4

JGPSHNTAP
4,204 Views

It's a little hard to troubleshoot if you are giving us working code and then telling us this doesn't work in the larger code.

storageguy
4,170 Views

It is the same code (is working). My problem with the output. When that block of code run alone (pasted on PS command prompt) it works fine. But when it is called after few other functions it shows only vserver data (no headings or other data).

 

Thanks

JGPSHNTAP
4,005 Views

I'm having trouble understanding because we can't see the entire code.  I ran you're code and it does work in my lab exactly as you stated.

 

If it's part of a larger script, it all depends on how your variables are defined, whether scoped properly.  

 

If you are not willing to share the entire script, than, at least for myself, I cannot assist

storageguy
3,974 Views

Thanks for you time, again. I think I found the issue. When I changed the preceeding function output, it corrected it self. 

Public